package com.infodms.dms.actions.claim.application;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

import com.infodms.dms.actions.claim.balanceAuditing.BalanceAuditing;
import com.infodms.dms.bean.AclUserBean;
import com.infodms.dms.bean.ClaimListBean;
import com.infodms.dms.bean.ClaimOrderBean;
import com.infodms.dms.bean.auditBean;
import com.infodms.dms.common.Constant;
import com.infodms.dms.common.DBLockUtil;
import com.infodms.dms.common.ErrorCodeConstant;
import com.infodms.dms.common.Utility;
import com.infodms.dms.common.getCompanyId.GetOemcompanyId;
import com.infodms.dms.common.materialManager.MaterialGroupManagerDao;
import com.infodms.dms.dao.claim.application.ClaimManualAuditingDao;
import com.infodms.dms.dao.claim.application.DealerBalanceDao;
import com.infodms.dms.dao.claim.auditing.BalanceAuditingDao;
import com.infodms.dms.dao.claim.auditing.ClaimAuditingDao;
import com.infodms.dms.dao.claim.dealerClaimMng.ClaimBillMaintainDAO;
import com.infodms.dms.exception.BizException;
import com.infodms.dms.po.FsFileuploadPO;
import com.infodms.dms.po.TcCodePO;
import com.infodms.dms.po.TcUserPO;
import com.infodms.dms.po.TmVehiclePO;
import com.infodms.dms.po.TtAsWrAppauthitemPO;
import com.infodms.dms.po.TtAsWrApplicationExtPO;
import com.infodms.dms.po.TtAsWrApplicationPO;
import com.infodms.dms.po.TtAsWrClaimBalancePO;
import com.infodms.dms.po.TtAsWrLabouritemPO;
import com.infodms.dms.po.TtAsWrNetitemExtPO;
import com.infodms.dms.po.TtAsWrNetitemPO;
import com.infodms.dms.po.TtAsWrPartsitemPO;
import com.infodms.dms.po.TtAsWrWrauthorizationPO;
import com.infodms.dms.util.CommonUtils; 
import com.infoservice.mvc.context.ActionContext;
import com.infoservice.mvc.context.RequestWrapper;
import com.infoservice.po3.bean.PageResult;

/**
 * 索赔申请单人工审核
 * @author XZM
 */
public class ClaimManualAuditing {
	
	private Logger logger = Logger.getLogger(ClaimManualAuditingDao.class);
	
	/** 索赔申请审核作业(授权审核) 查询首页面 */
	private final String MANUAL_AUDITING = "/jsp/claim/application/claimAuditIndex.jsp";
	/** 索赔单删除审核查询首页面 */
	private final String DEL_MANUAL_AUDITING = "/jsp/claim/application/deleteClaimAuditIndex.jsp";
	/** 索赔申请审核作业(授权审核) 首页面 */
	private final String MANUAL_AUDITING_PAGE = "/jsp/claim/application/claimAuditPage.jsp";
	/** 索赔申请审核作业（结算审核） 首页面 */
	private final String BALANCE_AUDITING_PAGE = "/jsp/claim/application/balanceAuditPage.jsp";
	/** 索赔申请审核作业（结算审核） 首页面 */
	private final String BALANCE_AUDITING_ONEBYONE = "/jsp/claim/application/balanceAuditOneByOne.jsp";
	/** 索赔申请重新审核作业(授权审核) 查询首页面 */
	private final String MANUAL_REAUDITING = "/jsp/claim/application/claimReAuditIndex.jsp";
	/** 索赔申请重新审核作业(授权审核) 首页面 */
	private final String MANUAL_REAUDITING_PAGE = "/jsp/claim/application/claimReAuditPage.jsp";
	/** 最长锁定时间（当有一用户进行结算时，其他用户不允许方法）分钟 */
	private static final Long lockLimit = 10L;

	/** 功能描述 */
	private String FUNCTION_DESC = "索赔申请审核作业";
	
	//结算室审核页面
	private final String accaudit = "/jsp/claim/application/accAudit.jsp";
	
	//索赔单审核页面
	private final String acconeaudit = "/jsp/claim/application/acconeAudit.jsp";

	/**
	 * 索赔申请审核作业 初始化
	 */
	public void claimManualAuditingInit(){
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		try{
			//取得该用户拥有的产地权限
			String yieldly = CommonUtils.findYieldlyByPoseId(logonUser.getPoseId());
			
			act.setOutData("yieldly", yieldly);
			act.setForword(this.MANUAL_AUDITING);
		} catch (Exception e){
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,this.FUNCTION_DESC);
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	
	/**
	 * Iverson add with 2010-11-15
	 * 索赔单删除审核初始化
	 */
	public void deleteClaimManualAuditingInit() {
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		try{
			//取得该用户拥有的产地权限
			String yieldly = CommonUtils.findYieldlyByPoseId(logonUser.getPoseId());
			
			act.setOutData("yieldly", yieldly);
			act.setForword(this.DEL_MANUAL_AUDITING);
		} catch (Exception e){
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,this.FUNCTION_DESC);
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	
	/**
	 * 索赔申请单查询
	 * 规则：索赔申请单状态 固定为"审核中"，只有该状态需要人工审核
	 * 2010-09-29 MODIFY XZM 限制数据权限（根据用户所属组织）
	 */
	public void claimManualAuditingQuery(){
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		ClaimManualAuditingDao maDao = new ClaimManualAuditingDao();
		try{
			//取得查询参数
			RequestWrapper request = act.getRequest();
			String dealerCode = request.getParamValue("dealerCode");//经销商代码（多个）
			String dealerName = request.getParamValue("DEALER_NAME");//经销商名称
			String roNo = request.getParamValue("CON_RO_NO");//工单号
			String lineNo = request.getParamValue("CON_LINE_NO");//行号
			String claimType = request.getParamValue("CLAIM_TYPE");//索赔类型
			String vin = request.getParamValue("CON_VIN");//车辆唯一标识码
			String applyStartDate = request.getParamValue("CON_APPLY_DATE_START");//申请日期范围（开始时间）
			String applyEndDate = request.getParamValue("CON_APPLY_DATE_END");//申请日期范围（结束时间）
			String claimStatus = Constant.CLAIM_APPLY_ORD_TYPE_03.toString();//状态 固定为 "审核中"
			String claimNo = request.getParamValue("CLAIM_NO");//索赔申请单号
			String yieldly = request.getParamValue("YIELDLY");//查询条件--产地
			String province = request.getParamValue("province");//省份CODE
			Long companyId = GetOemcompanyId.getOemCompanyId(logonUser);//用户所属公司
			String yieldlys = CommonUtils.findYieldlyByPoseId(logonUser.getPoseId());//该用户拥有的产地权限
			
			Long orgId = logonUser.getOrgId();//组织ID
			Long poseId = logonUser.getPoseId();//职位ID
			//查询职位中业务范围
			String areaIds = MaterialGroupManagerDao.getAreaIdsByPoseId(poseId);
			
			Long userId = logonUser.getUserId();
			TcUserPO userPO = maDao.queryUserById(userId);
			
			Integer count = maDao.getUserRegionCount(userId);
			
			String authCode = "";
			if(userPO.getApprovalLevelCode()!=null)
				authCode = userPO.getApprovalLevelCode().toString();//结算授权级别代码
			
			Integer curPage = request.getParamValue("curPage")==null?1
					:Integer.parseInt(request.getParamValue("curPage"));//分页首页代码
			
			if(Utility.testString(applyStartDate))
				applyStartDate = applyStartDate + " 00:00:00";
			
			if(Utility.testString(applyEndDate))
				applyEndDate = applyEndDate + " 23:59:59";
			
			ClaimOrderBean orderBean = new ClaimOrderBean();
			orderBean.setDealerCodes(dealerCode);
			orderBean.setDealerName(dealerName);
			orderBean.setRoNo(roNo);
			orderBean.setLineNo(lineNo);
			orderBean.setClaimType(claimType);
			orderBean.setVin(vin);
			orderBean.setApplyEndDate(applyEndDate);
			orderBean.setApplyStartDate(applyStartDate);
			orderBean.setClaimStatus(claimStatus);
			orderBean.setAuthCode(authCode);
			orderBean.setClaimNo(claimNo);
			orderBean.setCompanyId(companyId);
			orderBean.setPoseId(poseId);
			orderBean.setOrgId(orgId);
			orderBean.setAreaIds(CommonUtils.checkNull(areaIds));
			orderBean.setYieldly(yieldly);
			orderBean.setYieldlys(yieldlys);
			orderBean.setProvinceCode(province);
			orderBean.setUserId(String.valueOf(userId));
			PageResult<Map<String,Object>> result = null;
			//if(count==0){
				//result = maDao.queryClaimAudit(orderBean,curPage,Constant.PAGE_SIZE);
			//}else{
				result = maDao.queryClaimAudit1(orderBean,curPage,Constant.PAGE_SIZE);
			//}
			//查询索赔申请单

			
			act.setOutData("ps", result);
		} catch (Exception e){
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"索赔申请单上报");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	
	/**
	 * 查询出经销商端申请过来的删除索赔单
	 */
	public void deleteClaimManualAuditingQuery(){
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		ClaimManualAuditingDao maDao = new ClaimManualAuditingDao();
		try{
			//取得查询参数
			RequestWrapper request = act.getRequest();
			String dealerCode = request.getParamValue("dealerCode");//经销商代码（多个）
			String dealerName = request.getParamValue("DEALER_NAME");//经销商名称
			String roNo = request.getParamValue("CON_RO_NO");//工单号
			String lineNo = request.getParamValue("CON_LINE_NO");//行号
			String claimType = request.getParamValue("CLAIM_TYPE");//索赔类型
			String vin = request.getParamValue("CON_VIN");//车辆唯一标识码
			String applyStartDate = request.getParamValue("CON_APPLY_DATE_START");//申请日期范围（开始时间）
			String applyEndDate = request.getParamValue("CON_APPLY_DATE_END");//申请日期范围（结束时间）
			String claimStatus = Constant.CLAIM_APPLY_ORD_TYPE_03.toString();//状态 固定为 "审核中"
			String claimNo = request.getParamValue("CLAIM_NO");//索赔申请单号
			String yieldly = request.getParamValue("YIELDLY");//查询条件--产地
			String province = request.getParamValue("province");//省份CODE
			Long companyId = GetOemcompanyId.getOemCompanyId(logonUser);//用户所属公司
			String yieldlys = CommonUtils.findYieldlyByPoseId(logonUser.getPoseId());//该用户拥有的产地权限
			
			Long orgId = logonUser.getOrgId();//组织ID
			Long poseId = logonUser.getPoseId();//职位ID
			//查询职位中业务范围
			String areaIds = MaterialGroupManagerDao.getAreaIdsByPoseId(poseId);
			
			Long userId = logonUser.getUserId();
			TcUserPO userPO = maDao.queryUserById(userId);
			
			Integer count = maDao.getUserRegionCount(userId);
			
			String authCode = "";
			if(userPO.getApprovalLevelCode()!=null)
				authCode = userPO.getApprovalLevelCode().toString();//结算授权级别代码
			
			Integer curPage = request.getParamValue("curPage")==null?1
					:Integer.parseInt(request.getParamValue("curPage"));//分页首页代码
			
			if(Utility.testString(applyStartDate))
				applyStartDate = applyStartDate + " 00:00:00";
			
			if(Utility.testString(applyEndDate))
				applyEndDate = applyEndDate + " 23:59:59";
			
			ClaimOrderBean orderBean = new ClaimOrderBean();
			orderBean.setDealerCodes(dealerCode);
			orderBean.setDealerName(dealerName);
			orderBean.setRoNo(roNo);
			orderBean.setLineNo(lineNo);
			orderBean.setClaimType(claimType);
			orderBean.setVin(vin);
			orderBean.setApplyEndDate(applyEndDate);
			orderBean.setApplyStartDate(applyStartDate);
			orderBean.setClaimStatus(claimStatus);
			orderBean.setAuthCode(authCode);
			orderBean.setClaimNo(claimNo);
			orderBean.setCompanyId(companyId);
			orderBean.setPoseId(poseId);
			orderBean.setOrgId(orgId);
			orderBean.setAreaIds(CommonUtils.checkNull(areaIds));
			orderBean.setYieldly(yieldly);
			orderBean.setYieldlys(yieldlys);
			orderBean.setProvinceCode(province);
			orderBean.setUserId(String.valueOf(userId));
			PageResult<Map<String,Object>> result = null;
			//if(count==0){
				//result = maDao.queryClaimAuditDelete(orderBean,curPage,Constant.PAGE_SIZE);
			//}else{
				result = maDao.queryClaimAuditDelete1(orderBean,curPage,Constant.PAGE_SIZE);
			//}
			//查询索赔申请单

			
			act.setOutData("ps", result);
		} catch (Exception e){
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"索赔申请单上报");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	
	/**
	 * 审核索赔工单
	 * 注：该审核暂时屏蔽，新审核采用技术审核和结算室审核
	 * <pre>
	 * 步骤：
	 * 1、更新索赔之配件信息（结算金额）
	 * 2、更新索赔之工时信息（结算金额）
	 * 3、更新索赔之其他项目信息（结算金额）
	 * 4、记录审核授权状态过程
	 * 5、更新索赔申请单授权，将审核授权级别中审核完成的去掉
	 * 6、更新索赔申请单状态、下一步需要审核的级别和结算总金额
	 * </pre>
	 */
	@Deprecated
	public void manualAuditing(){
		
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);

		try{
			RequestWrapper request = act.getRequest();
			Long userId = logonUser.getUserId();//登陆用户ID
			String claimId = request.getParamValue("claimId");//索赔申请单ID
			String status = request.getParamValue("status");//审核状态(审核通过、审核退回、审核拒绝)
			String partIds[] = request.getParamValues("PART_ID");//索赔之配件信息ID
			String labourIds[] = request.getParamValues("LABOUR_ID");//索赔之工时信息ID
			String otherIds[] = request.getParamValues("OTHER_ID");//索赔之其他项目信息ID
			String partBlance[] = request.getParamValues("PARTAMOUNT");//索赔之配件结算金额
			String labourBlance[] = request.getParamValues("LOBOURAMOUNT");//索赔之工时结算金额
			String otherBlance[] = request.getParamValues("OTHERAMOUNT");//索赔之其他项目结算金额
			String auditCon[] = request.getParamValues("audit_con");//审核意见
			String remark = request.getParamValue("CON_REMARK");//审核意见
			
			if(this.isAuditing(claimId, userId)){//不可以再次审核，该索赔单已经审核过
				BizException e1 = new BizException(act,ErrorCodeConstant.QUERY_FAILURE_CODE,"该索赔单之前已经审核过，不能再次审核！");
				act.setException(e1);
				return;
			}else{
				//1、更新索赔之配件信息（结算金额）
				double pBlance = this.updatePartInfo(partIds,partBlance,userId);
				//2、更新索赔之工时信息（结算金额）
				double lBlance = this.updateLabourInfo(labourIds,labourBlance,userId);
				//3、更新索赔之其他项目信息（结算金额）
				double oBlance = this.updateOtherInfo(otherIds,otherBlance,userId,auditCon);
				
				double allBlance = pBlance + lBlance + oBlance;//结算总金额
				
				//4、记录审核授权状态过程
				this.recordAuthProcess(status,userId,claimId,remark," [授权审核]",false);
				//5、根据索赔申请单中当前审核步骤，确定下一审核步骤
				String nextCode = this.getNextAuthCode(claimId);
				//6、更新索赔申请单状态、下一步需要审核的级别和结算总金额
				this.updateClaimOrder(status,userId,allBlance,claimId,nextCode,remark);
			}
			act.setOutData("ACTION_RESULT", 1);
			act.setOutData("FORWORD_URL", this.MANUAL_AUDITING);
				
		} catch (Exception e){
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"索赔申请单审核");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
		
		System.out.println("人工审核");
	}
	
	/**
	 * 检测该用户是否可以审核该索赔单或该索赔单是否已经审核过
	 * @param claimId 索赔单ID
	 * @param userId 用户ID
	 * @return true : 审核过或没有权限 false : 可以审核
	 */
	private boolean isAuditing(String claimId,Long userId){
		boolean result = false;
		
		ClaimManualAuditingDao mAuditingDao = new ClaimManualAuditingDao();
		TcUserPO userPO = mAuditingDao.queryUserById(userId);
		
		ClaimAuditingDao auditingDao = ClaimAuditingDao.getInstance();
		TtAsWrApplicationPO claimPO = auditingDao.queryClaimById(claimId);
		
		if(userPO==null || claimPO==null){
			result = true;
		}else{
			String userCode = "";
			if(userPO.getApprovalLevelCode()!=null)
				userCode = userPO.getApprovalLevelCode().toString();//结算授权级别代码
			String needCode = claimPO.getAuthCode();//该索赔单需要审核的级别
			if(userCode==null || "".equals(userCode) ||!userCode.equals(needCode)){
				//该用户的审核级别同索赔单需要的审核级别不同时，不允许审核
				result = true;
			}
		}
		
		return result;
	}
	
	/**
	 * 检测该用户是否可以审核该索赔单或该索赔单是否已经审核过
	 * @param claimId 索赔单ID
	 * @param userId 用户ID
	 * @return true : 审核过或没有权限 false : 可以审核
	 */
	private boolean isBalanceAuditing(String claimId,Long userId,String isRedo){
		boolean result = false;
		if(isRedo.equals("YES")){
			return false;
		}
		ClaimManualAuditingDao mAuditingDao = new ClaimManualAuditingDao();
		TcUserPO userPO = mAuditingDao.queryUserById(userId);
		
		ClaimAuditingDao auditingDao = ClaimAuditingDao.getInstance();
		TtAsWrApplicationPO claimPO = auditingDao.queryClaimById(claimId);
		
		if(userPO==null || claimPO==null){
			result = true;
		}else{
			String userCode = "";
			if(userPO.getBalanceLevelCode()!=null)
				userCode = userPO.getBalanceLevelCode().toString();//结算授权级别代码
			
			String needCode = claimPO.getAuthCode();//该索赔单需要审核的级别
			if(userCode==null || "".equals(userCode) ||!userCode.equals(needCode)){
				//该用户的审核级别同索赔单需要的审核级别不同时，不允许审核
				result = true;
			}
		}
		
		return result;
	}
	
	/**
	 * 更新索赔之配件信息
	 * @param partIds 配件ID集合
	 * @param partBlance ID对应结算金额
	 * @param userId 审核用户ID
	 * @return double 配件结算总金额
	 */
	private double updatePartInfo(String partIds[],String partBlance[],Long userId){
		double blance = 0.0;
		if(partIds!=null&&partBlance!=null){
			ClaimManualAuditingDao mAuditingDao = new ClaimManualAuditingDao();
			for (int i = 0; i < partIds.length; i++) {
				if(partBlance[i]!=null && !"".equals(partBlance[i])){
					blance = blance + Double.parseDouble(partBlance[i]);
					TtAsWrPartsitemPO partPO = new TtAsWrPartsitemPO();
					partPO.setBalanceAmount(Double.parseDouble(partBlance[i]));
					partPO.setUpdateBy(userId);
					partPO.setUpdateDate(new Date());
					mAuditingDao.updatePartsInfo(partPO, Long.parseLong(partIds[i]));
				}	
			}
		}
		return blance;
	}
	
	/**
	 * 更新索赔之配件信息
	 * @param partIds 配件ID集合
	 * @param partBlance ID对应结算金额
	 * @param partCount ID对应结算配件数量
	 * @param userId 审核用户ID
	 * @return double 配件结算总金额
	 */
	private double updatePartInfo(String partIds[],String partBlance[],String partCount[],String remark[],Long userId){
		double blance = 0.0;
		if(partIds!=null&&partBlance!=null){
			ClaimManualAuditingDao mAuditingDao = new ClaimManualAuditingDao();
			for (int i = 0; i < partIds.length; i++) {
				if(partBlance[i]!=null && !"".equals(partBlance[i])){
					blance = blance + Double.parseDouble(formateData(partBlance[i],"0"));
					TtAsWrPartsitemPO partPO = new TtAsWrPartsitemPO();
					partPO.setBalanceAmount(Double.parseDouble(formateData(partBlance[i],"0")));
					partPO.setBalanceQuantity(Float.parseFloat(formateData(partCount[i],"0")));
					partPO.setAuthRemark(CommonUtils.checkNull(remark[i]));
					partPO.setUpdateBy(userId);
					partPO.setUpdateDate(new Date());
					mAuditingDao.updatePartsInfo(partPO, Long.parseLong(partIds[i]));
				}	
			}
		}
		return blance;
	}
	
	/**
	 * 格式化数据
	 * @param value 原数据
	 * @param defaultValue 为空时使用的默认值
	 * @return
	 */
	private String formateData(String value,String defaultValue){
		String result = defaultValue;
		if(Utility.testString(value))
			result = value;
		return result;
	}
	
	/**
	 * 根据技术室审核结果，更新配件金额
	 * @param partIds 配件ID集合
	 * @param partBlance ID对应结算金额
	 * @param partStatus 对应配件的状态
	 * @param partCount 配件的结算数量
	 * @param userId 审核用户ID
	 * @return double 配件结算总金额
	 */
	private double updatePartInfoByStatus(String partIds[],String partBlance[],
			String partStatus[],String partCount[],Long userId){
		double blance = 0.0;
		if(partIds!=null&&partBlance!=null){
			ClaimManualAuditingDao mAuditingDao = new ClaimManualAuditingDao();
			for (int i = 0; i < partIds.length; i++) {
				
				TtAsWrPartsitemPO partPO = new TtAsWrPartsitemPO();
				partPO.setUpdateBy(userId);
				partPO.setUpdateDate(new Date());
				partPO.setIsAgree(Integer.parseInt(partStatus[i]));
				
				if(partBlance[i]!=null && !"".equals(partBlance[i]) 
						&& (Constant.IF_TYPE_YES.toString()).equals(partStatus[i])){
					//当授权审核同意，且结算金额不为空，那么更新索赔单
					blance = blance + Double.parseDouble(formateData(partBlance[i],"0"));
					partPO.setBalanceAmount(Double.parseDouble(formateData(partBlance[i],"0")));
					partPO.setBalanceQuantity(Float.parseFloat(formateData(partCount[i],"0")));
					/**addUser:xiongchuan addDate:2010-12-14 **/
					partPO.setQuantity(Float.parseFloat(formateData(partCount[i],"0")));
					partPO.setAmount(Double.parseDouble(formateData(partBlance[i],"0")));
					/**endUser:xiongchuan endDate:2010-12-14 **/
				}else{//当授权审核不同意时，将结算金额修改为0
					partPO.setBalanceAmount(0.0);
					partPO.setBalanceQuantity(0.0f);
					/**addUser:xiongchuan addDate:2010-12-14 **/
					partPO.setAmount(0.0);
					partPO.setQuantity(0.0f);
					/**endUser:xiongchuan endDate:2010-12-14 **/
				}
				
				mAuditingDao.updatePartsInfo(partPO, Long.parseLong(partIds[i]));
				
			}
		}
		
		return blance;
	}
	
	/**
	 * 更新索赔之工时信息
	 * @param labourIds 工时ID集合
	 * @param labourBlance ID对应结算金额
	 * @param userId 审核用户ID
	 * @return double 工时结算总金额
	 */
	private double updateLabourInfo(String labourIds[],String labourBlance[],Long userId){
		double blance = 0.0;
		if(labourIds!=null&&labourBlance!=null){
			ClaimManualAuditingDao mAuditingDao = new ClaimManualAuditingDao();
			for (int i = 0; i < labourIds.length; i++) {
				if(labourBlance[i]!=null && !"".equals(labourBlance[i])){
					blance = blance + Double.parseDouble(formateData(labourBlance[i],"0"));
					TtAsWrLabouritemPO labourPO = new TtAsWrLabouritemPO();
					labourPO.setBalanceAmount(Double.parseDouble(formateData(labourBlance[i],"0")));
					labourPO.setUpdateBy(userId);
					labourPO.setUpdateDate(new Date());
					mAuditingDao.updateLabourInfo(labourPO, Long.parseLong(labourIds[i]));
				}	
			}
		}
		return blance;
	}
	
	/**
	 * 更新索赔之工时信息
	 * @param labourIds 工时ID集合
	 * @param labourBlance ID对应结算金额
	 * @param labourCount ID对应结算工时数量
	 * @param userId 审核用户ID
	 * @return double 工时结算总金额
	 */
	private double updateLabourInfo(String labourIds[],String labourBlance[],String labourCount[],String remark[],Long userId){
		double blance = 0.0;
		if(labourIds!=null&&labourBlance!=null){
			ClaimManualAuditingDao mAuditingDao = new ClaimManualAuditingDao();
			for (int i = 0; i < labourIds.length; i++) {
				if(labourBlance[i]!=null && !"".equals(labourBlance[i])){
					blance = blance + Double.parseDouble(formateData(labourBlance[i],"0"));
					TtAsWrLabouritemPO labourPO = new TtAsWrLabouritemPO();
					labourPO.setBalanceAmount(Double.parseDouble(formateData(labourBlance[i],"0")));
					labourPO.setBalanceQuantity(Float.parseFloat(formateData(labourCount[i],"0")));
					//labourPO.setAuthRemark(CommonUtils.checkNull(remark[i]));
					labourPO.setUpdateBy(userId);
					labourPO.setUpdateDate(new Date());
					mAuditingDao.updateLabourInfo(labourPO, Long.parseLong(labourIds[i]));
				}	
			}
		}
		return blance;
	}
	/**
	 * 根据技术室审核结果，更新工时金额
	 * @param labourIds 工时ID集合
	 * @param labourBlance ID对应结算金额
	 * @param labourStatus 对应工时的审核状态
	 * @param labourCount 对应结算工时数
	 * @param userId 审核用户ID
	 * @return double 工时结算总金额
	 */
	private double updateLabourInfoByStatus(String labourIds[],String labourBlance[],
			String labourStatus[],String labourCount[],Long userId){
		double blance = 0.0;
		if(labourIds!=null&&labourBlance!=null){
			ClaimManualAuditingDao mAuditingDao = new ClaimManualAuditingDao();
			for (int i = 0; i < labourIds.length; i++) {
				
				TtAsWrLabouritemPO labourPO = new TtAsWrLabouritemPO();
				labourPO.setUpdateBy(userId);
				labourPO.setUpdateDate(new Date());
				labourPO.setIsAgree(Integer.parseInt(labourStatus[i]));
				
				if(labourBlance[i]!=null && !"".equals(labourBlance[i])
						&& (Constant.IF_TYPE_YES.toString()).equals(labourStatus[i])){
					//当授权审核同意，且结算金额不为空，那么更新索赔单
					blance = blance + Double.parseDouble(formateData(labourBlance[i],"0"));
					labourPO.setBalanceAmount(Double.parseDouble(formateData(labourBlance[i],"0")));
					labourPO.setBalanceQuantity(Float.parseFloat(formateData(labourCount[i],"0")));
					labourPO.setLabourAmount(Double.parseDouble(formateData(labourBlance[i],"0")));
					labourPO.setLabourQuantity(Float.parseFloat(formateData(labourCount[i],"0")));
				}else{//当授权审核不同意时，将结算金额修改为0
					labourPO.setBalanceAmount(0.0);
					labourPO.setBalanceQuantity(0f);
					labourPO.setLabourAmount(0.0);
					labourPO.setLabourQuantity(0f);
				}
				
				mAuditingDao.updateLabourInfo(labourPO, Long.parseLong(labourIds[i]));
			}
		}
		return blance;
	}
	
	/**
	 * 更新索赔之其他项目信息
	 * @param otherIds 其他项目ID集合
	 * @param otherBlance ID对应结算金额
	 * @param userId 审核用户ID
	 * @return double 其他项目结算总金额
	 */
	private double updateOtherInfo(String otherIds[],String otherBlance[],Long userId,String[] auditCon){
		double blance = 0.0;
		if(otherIds!=null&&otherBlance!=null){
			ClaimManualAuditingDao mAuditingDao = new ClaimManualAuditingDao();
			for (int i = 0; i < otherIds.length; i++) {
				if(otherBlance[i]!=null && !"".equals(otherBlance[i])){
					blance = blance + Double.parseDouble(otherBlance[i]);
					TtAsWrNetitemPO otherPO = new TtAsWrNetitemPO();
					otherPO.setBalanceAmount(Double.parseDouble(otherBlance[i]));
					otherPO.setUpdateBy(userId);
					otherPO.setUpdateDate(new Date());
					if(auditCon!=null){
						otherPO.setAuditCon(auditCon[i]);
					}
					mAuditingDao.updateOtherInfo(otherPO, Long.parseLong(otherIds[i]));
				}	
			}
		}
		return blance;
	}
	
	/**
	 * 更新索赔之其他项目信息
	 * @param otherIds 其他项目ID集合
	 * @param otherBlance ID对应结算金额
	 * @param otherStatus 其他项目审核状态
	 * @param userId 审核用户ID
	 * @return double 其他项目结算总金额
	 */
	private double updateOtherInfoByStatus(String otherIds[],String otherBlance[],String otherStatus[],Long userId){
		double blance = 0.0;
		if(otherIds!=null&&otherBlance!=null){
			ClaimManualAuditingDao mAuditingDao = new ClaimManualAuditingDao();
			for (int i = 0; i < otherIds.length; i++) {
				
				TtAsWrNetitemPO otherPO = new TtAsWrNetitemPO();
				otherPO.setUpdateBy(userId);
				otherPO.setUpdateDate(new Date());
				//页面已隐藏，默认为   是
				//otherPO.setIsAgree(Integer.parseInt(otherStatus[i]));
				otherPO.setIsAgree(Constant.IF_TYPE_YES);
				if(otherBlance[i]!=null && !"".equals(otherBlance[i])
						&& (Constant.IF_TYPE_YES.toString()).equals(otherStatus[i])){
					//当授权审核同意，且结算金额不为空，那么更新索赔单
					blance = blance + Double.parseDouble(otherBlance[i]);
					otherPO.setBalanceAmount(Double.parseDouble(otherBlance[i]));
					otherPO.setAmount(Double.parseDouble(otherBlance[i]));
				}else{//当授权审核不同意时，将结算金额修改为0
					otherPO.setBalanceAmount(0.0);
					otherPO.setAmount(0.0);
				}
				
				mAuditingDao.updateOtherInfo(otherPO, Long.parseLong(otherIds[i]));
			}
		}
		return blance;
	}
	
	/**
	 * 记录审核记录
	 * @param status 审核结果状态
	 * @param userId 审核人员
	 * @param claimId 索赔申请单ID
	 * @param backup 备注
	 * @param authType 审核类型
	 */
	private void recordAuthProcess(String status,Long userId,
			String claimId,String backup,String authType,boolean isBalance){
		
		ClaimAuditingDao auditingDao = ClaimAuditingDao.getInstance();
		ClaimManualAuditingDao mAuditingDao = new ClaimManualAuditingDao();
		
		TcUserPO userPO = mAuditingDao.queryUserById(userId);
		String authCode = "";
		if(userPO.getApprovalLevelCode()!=null && !isBalance)
			authCode = userPO.getApprovalLevelCode().toString();//结算授权级别代码
		else if(userPO.getBalanceLevelCode()!=null && isBalance)
			authCode = userPO.getBalanceLevelCode().toString();
		
		TtAsWrAppauthitemPO appAuthPO = new TtAsWrAppauthitemPO();
		appAuthPO.setId(Long.parseLong(claimId));
		appAuthPO.setApprovalPerson(userPO.getName()+authType);
		appAuthPO.setApprovalLevelCode(authCode);
		appAuthPO.setApprovalDate(new Date());
		appAuthPO.setApprovalResult(status);//授权结果=索赔申请单状态
		appAuthPO.setAuthorizedCode(userPO.getPersonCode());//授权代码
		appAuthPO.setRemark(backup);//备注=审核不通过理由
		appAuthPO.setCreateBy(userId);
		appAuthPO.setCreateDate(new Date());
		auditingDao.insertClaimAppAuth(appAuthPO);
	}
	
	/**
	 * 取的下一审核需要的授权级别
	 * @param claimId 索赔工单ID
	 * @param userId 用户信息
	 * @return String 下一审核授权级别
	 */
	private String getNextAuthCode(String claimId){
		
		String nextAuthCode = "";
		ClaimAuditingDao auditingDao = ClaimAuditingDao.getInstance();
		ClaimBillMaintainDAO billDao = new ClaimBillMaintainDAO();
		
		//索赔申请单信息
		TtAsWrApplicationPO claimPO = auditingDao.queryClaimById(claimId);
		String authCode = claimPO.getAuthCode();
		if(authCode==null)
			return nextAuthCode;
		//索赔审核需要授权信息
		TtAsWrWrauthorizationPO authPO = billDao.queryAuthReason(claimId);
		String levelCode = "";
		
		if(authPO!=null)
			levelCode = authPO.getApprovalLevelCode();
		
		//取得下一级需要审核的代码
		if(levelCode!=null && !"".equals(levelCode)){
			int index = levelCode.indexOf(authCode);
			
			if(index>-1)
				index = index + authCode.length();
			
			levelCode = levelCode.substring(index);
			
			if(levelCode!=null && !"".equals(levelCode)){
				while(levelCode.startsWith(",")){
					levelCode = levelCode.replaceFirst(",", "");
				}
				if(levelCode.indexOf(",")>-1){
					nextAuthCode = levelCode.split(",")[0];
				}else{
					nextAuthCode = levelCode;
				}
			}
		}
		return nextAuthCode;
	}
	
	/**
	 * 取的下一审核需要的授权级别
	 * @param claimId 索赔工单ID
	 * @param userId 用户信息
	 * @return String 下一审核授权级别
	 * @throws Exception 
	 */
	private String getNextAuthCode(TtAsWrApplicationPO claimPO) throws Exception{
		
		if(claimPO==null || claimPO.getId()==null)
			throw new Exception("索赔单信息空！");
		
		String nextAuthCode = "";
		ClaimBillMaintainDAO billDao = new ClaimBillMaintainDAO();
		
		//索赔申请单信息
		String authCode = claimPO.getAuthCode();
		//索赔审核需要授权信息
		TtAsWrWrauthorizationPO authPO = billDao.queryAuthReason(claimPO.getId().toString());
		String levelCode = "";
		
		if(authPO!=null)
			levelCode = authPO.getApprovalLevelCode();
		
		//取得下一级需要审核的代码
		if(levelCode!=null && !"".equals(levelCode)){
			int index = levelCode.indexOf(authCode);
			
			if(index>-1)
				index = index + authCode.length();
			
			levelCode = levelCode.substring(index);
			
			if(levelCode!=null && !"".equals(levelCode)){
				while(levelCode.startsWith(",")){
					levelCode = levelCode.replaceFirst(",", "");
				}
				if(levelCode.indexOf(",")>-1){
					nextAuthCode = levelCode.split(",")[0];
				}else{
					nextAuthCode = levelCode;
				}
			}
		}
		return nextAuthCode;
	}
	
	/**
	 * 更新索赔申请单信息
	 * <pre>
	 * 注意：
	 *     审核过程中有一个级别上做出审核拒绝或审核退回后则不再进行其他级别审核
	 *     如果审核通过则进行下一个级别的审核
	 * </pre>
	 * @param status 索赔申请单状态
	 * @param userId 审核用户
	 * @param allBlance 结算金额
	 * @param claimId 索赔申请单ID
	 * @param nextCode 需要审核的下个级别
	 * @param remark 审核意见
	 */
	private void updateClaimOrder(String status,Long userId,double allBlance,
			String claimId,String nextCode,String remark){
		TtAsWrApplicationPO claimPO = new TtAsWrApplicationPO();
		claimPO.setBalanceAmount(allBlance);
		claimPO.setUpdateBy(userId);
		claimPO.setAuditingMan(userId);
		claimPO.setUpdateDate(new Date());
		claimPO.setAuthCode(nextCode);
		claimPO.setAuditType(Constant.IS_MANUAL_AUDITING+"");//人工审核标识
		if(Constant.CLAIM_APPLY_ORD_TYPE_05.toString().equals(status)){//审核拒绝 则 不在进行其他审核
			claimPO.setStatus(Integer.parseInt(status));
			claimPO.setLastStatus(Integer.parseInt(status));
			claimPO.setOemOption(remark);
		}else if(Constant.CLAIM_APPLY_ORD_TYPE_06.toString().equals(status)){//审核退回 则不在进行其他审核
			claimPO.setStatus(Integer.parseInt(status));
			claimPO.setLastStatus(Integer.parseInt(status));
			claimPO.setOemOption(remark);
		}else{//审核通过
			if(nextCode==null || "".equals(nextCode)){//不存在其他需要审核的级别
				claimPO.setStatus(Integer.parseInt(status));
				claimPO.setLastStatus(Integer.parseInt(status));
			}
		}
		
		ClaimManualAuditingDao mAuditingDao = new ClaimManualAuditingDao();
		mAuditingDao.updateClaimInfo(claimPO, Long.parseLong(claimId));
	}
	
	/**
	 * 更新索赔申请单信息
	 * <pre>
	 * 注意：
	 *     审核过程中有一个级别上做出审核拒绝或审核退回后则不再进行其他级别审核
	 *     如果审核通过则进行下一个级别的审核
	 * </pre>
	 * @param status 索赔申请单状态
	 * @param userId 审核用户
	 * @param allBlance 结算金额
	 * @param claimId 索赔申请单ID
	 * @param nextCode 需要审核的下个级别
	 * @param remark 审核意见
	 * @param appendLabourNum 追加工时数
	 * @param companyId 公司ID
	 */
	@SuppressWarnings("unused")
	@Deprecated
	private void updateClaimOrder(String status,Long userId,double allBlance,
			String claimId,String nextCode,String remark,String appendLabourNum,
			Long companyId){
		
		TtAsWrApplicationPO claimPO = new TtAsWrApplicationPO();
		claimPO.setUpdateBy(userId);
		claimPO.setUpdateDate(new Date());
		claimPO.setAuthCode(nextCode);
		claimPO.setAuditType(Constant.IS_MANUAL_AUDITING+"");//人工审核标识
		if(appendLabourNum==null || "".equals(appendLabourNum))
			appendLabourNum = "0";
		claimPO.setAppendlabourNum(CommonUtils.parseDouble(appendLabourNum));
		//计算工时费用,同时将追加费用加入到结算金额中
		Double price = (new LabourUtil()).getLabourPrice(claimId, companyId);
		Double amount = price * CommonUtils.parseDouble(appendLabourNum);
		claimPO.setAppendlabourAmount(amount);
		
		claimPO.setBalanceAmount(allBlance+claimPO.getAppendlabourAmount());
		
		if(Constant.CLAIM_APPLY_ORD_TYPE_05.toString().equals(status)){//审核拒绝 则 不在进行其他审核
			claimPO.setStatus(Integer.parseInt(status));
			claimPO.setOemOption(remark);
		}else if(Constant.CLAIM_APPLY_ORD_TYPE_06.toString().equals(status)){//审核退回 则不在进行其他审核
			claimPO.setStatus(Integer.parseInt(status));
			claimPO.setOemOption(remark);
		}else{//审核通过
			if(nextCode==null || "".equals(nextCode)){//不存在其他需要审核的级别
				claimPO.setStatus(Integer.parseInt(status));
			}
		}
		
		ClaimManualAuditingDao mAuditingDao = new ClaimManualAuditingDao();
		mAuditingDao.updateClaimInfo(claimPO, Long.parseLong(claimId));
	}
	
	/**
	 * 更新索赔申请单信息
	 * <pre>
	 * 注意：
	 *     审核过程中有一个级别上做出审核拒绝或审核退回后则不再进行其他级别审核
	 *     如果审核通过则进行下一个级别的审核
	 * </pre>
	 * @param nextCode 需要审核的下个级别
	 * @param appendLabourNum 追加工时数
	 * @param labourPrice 工时单价
	 * @param conditionPO 需要传入参数[索赔申请单状态、审核用户(更新用户ID)、结算金额、索赔申请单ID、
	 * 					  审核意见]
	 */
	private void updateClaimOrder(String nextCode,String appendLabourNum,
			Double labourPrice,TtAsWrApplicationPO conditionPO){
		
		String status = CommonUtils.checkNull(conditionPO.getStatus());
		Long userId = conditionPO.getUpdateBy();
		double allBlance = conditionPO.getBalanceAmount();
		String claimId = CommonUtils.checkNull(conditionPO.getId());
		String remark = CommonUtils.checkNull(conditionPO.getRemark());
		
		TtAsWrApplicationPO claimPO = new TtAsWrApplicationPO();
		claimPO.setUpdateBy(userId);
		claimPO.setUpdateDate(new Date());
		claimPO.setAuditingMan(userId);
		claimPO.setAuthCode(nextCode);
		claimPO.setAuditType(Constant.IS_MANUAL_AUDITING+"");//人工审核标识
		claimPO.setAuditingDate(new Date());
		if(appendLabourNum==null || "".equals(appendLabourNum))
			appendLabourNum = "0";
		claimPO.setAppendlabourNum(CommonUtils.parseDouble(appendLabourNum));
		//计算工时费用,同时将追加费用加入到结算金额中
		Double amount = labourPrice * CommonUtils.parseDouble(appendLabourNum);
		claimPO.setAppendlabourAmount(amount);
		claimPO.setAppendLabourAmountBck(amount);//Iverson add By 2010-12-13
		/**addUser:xiongchuan addDate:2010-12-14        **/
		claimPO.setApplyAppendlabourAmount(amount);
		claimPO.setBalanceAppendlabourAmount(amount);
		/**endUser:xiongchuan endDate:2010-12-14       **/
		claimPO.setBalanceAmount(allBlance+claimPO.getAppendlabourAmount());
		claimPO.setBalanceAmountBck(allBlance+claimPO.getAppendlabourAmount());//Iverson add By 2010-12-13
		if(Constant.CLAIM_APPLY_ORD_TYPE_05.toString().equals(status)){//审核拒绝 则 不在进行其他审核
			claimPO.setStatus(Integer.parseInt(status));
			claimPO.setLastStatus(Integer.parseInt(status));
			claimPO.setOemOption(remark);
		}else if(Constant.CLAIM_APPLY_ORD_TYPE_06.toString().equals(status)){//审核退回 则不在进行其他审核
			claimPO.setStatus(Integer.parseInt(status));
			claimPO.setLastStatus(Integer.parseInt(status));
			claimPO.setOemOption(remark);
		}else{//审核通过
			if(nextCode==null || "".equals(nextCode)){//不存在其他需f要审核的级别
				claimPO.setLastStatus(Integer.parseInt(status));
				claimPO.setStatus(Integer.parseInt(status));
			}
		}
		
		ClaimManualAuditingDao mAuditingDao = new ClaimManualAuditingDao();
		mAuditingDao.updateClaimInfo(claimPO, Long.parseLong(claimId));
		
	}
	
	/**
	 * 跳转到索赔审核页(授权审核)
	 * @throws
	 */
	public void claimAuditingPage() {
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean) act.getSession().get(
				Constant.LOGON_USER);
		try {
			ClaimBillMaintainDAO dao = ClaimBillMaintainDAO.getInstance();
			ClaimManualAuditingDao auditingDao = new ClaimManualAuditingDao();
			
			RequestWrapper request = act.getRequest();
			String id = request.getParamValue("ID");
			String isAudit = request.getParamValue("isAudit");//是否是索赔审核（true:是，false:索赔明细查询）
			String isReAuditing = request.getParamValue("isReAuditing");//是否是重新审核
			TtAsWrApplicationExtPO tawep = auditingDao.queryClaimOrderDetailById(id);
			List<Map<String, Object>> customerList = dao.getVinUserName(CommonUtils.checkNull(tawep.getVin()));
			Map<String,Object> customerMap = new HashMap<String, Object>();
			if(customerList!=null && customerList.size()>0)
				customerMap = customerList.get(0);
			
			/******add by liuxh 20101125 roduct date*****/
			TmVehiclePO veh=new TmVehiclePO();
			veh.setVin(tawep.getVin());
			TmVehiclePO vehSel=(TmVehiclePO)auditingDao.select(veh).get(0);
			/******add by liuxh 20101125 product date*****/
			
			//取得产地名称
			String yieldly = tawep.getYieldly();
			String yieldlyName = "";
			if(yieldly!=null){
				TcCodePO codePO = CommonUtils.findTcCodeDetailByCodeId(CommonUtils.parseInteger(yieldly));
				if(codePO!=null && codePO.getCodeDesc()!=null)
					yieldlyName = codePO.getCodeDesc();
			}
			tawep.setYieldlyName(yieldlyName);
			
			List<ClaimListBean> partls = dao.queryPartById(id); //取配件信息
			List<ClaimListBean> itemls = dao.queryItemById(id); //取工时
			List<TtAsWrNetitemExtPO> otherls = dao.queryOtherByid(id);//取其他项目
			List<FsFileuploadPO> attachLs = dao.queryAttById(id);//取得附件
			List<TtAsWrAppauthitemPO> appAuthls = dao.queryAppAuthInfo(id);//审核授权信息
			TtAsWrWrauthorizationPO authReason = dao.queryAuthReason(id);//需要授权原因
			List<TcCodePO> statusList =  CommonUtils.findTcCodeByType(Integer.parseInt(Constant.IF_TYPE));//是否同意状态
			
			act.setOutData("application", tawep);
			act.setOutData("attachLs", attachLs);
			act.setOutData("ID", id);//索赔申请单ID
			act.setOutData("itemLs", itemls);//索赔单之工时信息
			act.setOutData("partLs", partls);//索赔单之配件信息
			act.setOutData("otherLs",otherls);//索赔单之其他项目信息
			act.setOutData("appAuthls",appAuthls);//索赔单之审核信息
			act.setOutData("authReason",authReason);//索赔单之审核原因
			act.setOutData("statusList", statusList);//是否同意状态
			act.setOutData("isAudit", isAudit);//true:审核页面 false:明细查询页面
			act.setOutData("customerMap", customerMap);//客户信息
			/********add by liuxh 20101125 *******/
			act.setOutData("vehSel", vehSel);//add vehcel
			/********add by liuxh 20101125 *******/
			
			//zhumingwei 2011-03-11  此方法用于区分轿车和微车
			TcCodePO codePo= new TcCodePO();
			codePo.setType(Constant.chana+"");
			TcCodePO poValue = (TcCodePO)dao.select(codePo).get(0);
			String codeId = poValue.getCodeId();
			act.setOutData("codeId", Integer.parseInt(codeId));
			//zhumingwei 2011-03-11
			
			act.setOutData("curPage", request.getParamValue("page"));
			if("true".equals(isReAuditing)){//转重新审核
				act.setForword(this.MANUAL_REAUDITING_PAGE);
			}else{//转换授权审核
				act.setForword(this.MANUAL_AUDITING_PAGE);
			}
			
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "索赔单状态跟踪");
			logger.error(logonUser, e1);
			act.setException(e1);
		}
	}

	/**
	 * 技术室授权审核
	 * <pre>
	 * 步骤：
	 * 1、更新索赔之配件信息（结算金额）
	 * 2、更新索赔之工时信息（结算金额）
	 * 3、更新索赔之其他项目信息（结算金额）
	 * 4、记录审核授权状态过程
	 * 5、更新索赔申请单授权，将审核授权级别中审核完成的去掉
	 * 6、更新索赔申请单状态、下一步需要审核的级别和结算总金额
	 * </pre>
	 */
	public void engineeringAuditing(){
		
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);

		try{
			RequestWrapper request = act.getRequest();
			Long userId = logonUser.getUserId();//登陆用户ID
			String claimId = request.getParamValue("claimId");//索赔申请单ID
			String status = request.getParamValue("status");//审核状态(审核通过、审核退回、审核拒绝)
			String partIds[] = request.getParamValues("PART_ID");//索赔之配件信息ID
			String labourIds[] = request.getParamValues("LABOUR_ID");//索赔之工时信息ID
			String otherIds[] = request.getParamValues("OTHER_ID");//索赔之其他项目信息ID
			String partBlance[] = request.getParamValues("PARTAMOUNTTD");//索赔之配件结算金额
			String labourBlance[] = request.getParamValues("LOBOURAMOUNTTD");//索赔之工时结算金额
			String otherBlance[] = request.getParamValues("OTHERAMOUNTTD");//索赔之其他项目结算金额
			String partStatus[] = request.getParamValues("PARTSTATUS");//索赔之配件结算金额
			String labourStatus[] = request.getParamValues("LOBOURSTATUS");//索赔之工时结算金额
			String otherStatus[] = request.getParamValues("OTHERSTATUS");//索赔之其他项目结算金额
			String partCount[] = request.getParamValues("PARTBCOUNTTD");//索赔之配件结算数量
			String labourCount[] = request.getParamValues("LABOURBCOUNTTD");//索赔之工时结算数量
			String remark = request.getParamValue("CON_REMARK");//审核意见
			String appendLabour = request.getParamValue("APPEND_LABOUR");//追加工时数
			String labourPrice = request.getParamValue("labourPrice");//工时单价
			
			remark = CommonUtils.checkNull(remark) + " [追加工时数：" +appendLabour+ "]";
			
			if(this.isAuditing(claimId, userId)){//不可以再次审核，该索赔单已经审核过
				BizException e1 = new BizException(act,ErrorCodeConstant.QUERY_FAILURE_CODE,"该索赔单之前已经审核过，不能再次审核！");
				act.setException(e1);
				return;
			}else{
				//1、更新索赔之配件信息（结算金额）
				double pBlance = this.updatePartInfoByStatus(partIds,partBlance,partStatus,partCount,userId);
				//2、更新索赔之工时信息（结算金额）
				double lBlance = this.updateLabourInfoByStatus(labourIds,labourBlance,labourStatus,labourCount,userId);
				//3、更新索赔之其他项目信息（结算金额）
				double oBlance = this.updateOtherInfoByStatus(otherIds,otherBlance,otherStatus,userId);
				
				double allBlance = pBlance + lBlance + oBlance;//结算总金额
				
				//4、记录审核授权状态过程
				this.recordAuthProcess(status,userId,claimId,remark," [授权审核]",false);
				//5、根据索赔申请单中当前审核步骤，确定下一审核步骤
				String nextCode = this.getNextAuthCode(claimId);
				//6、更新索赔申请单状态、下一步需要审核的级别和结算总金额
				TtAsWrApplicationPO conditionPO = new TtAsWrApplicationPO();
				conditionPO.setStatus(Integer.parseInt(status));
				conditionPO.setUpdateBy(userId);
				conditionPO.setBalanceAmount(allBlance);
				conditionPO.setLabourAmount(lBlance);//更新
				conditionPO.setPartAmount(pBlance);
				conditionPO.setRemark(remark);
				conditionPO.setId(Long.parseLong(claimId));
				if(!Utility.testString(labourPrice)||Constant.CLAIM_APPLY_ORD_TYPE_06.toString().equals(status))
					labourPrice = "0";
				if(Constant.CLAIM_APPLY_ORD_TYPE_06.toString().equals(status))
					appendLabour = "0";
				this.updateClaimOrder(nextCode,appendLabour,Double.parseDouble(labourPrice),conditionPO);
				//61、当审核状态为"退回"时，修改对应工单的状态为"未上报"(现在工单转索赔单后就不可以在修改了)
				/*if(Constant.CLAIM_APPLY_ORD_TYPE_06.toString().equals(status)){
					ClaimAuditingDao auditingDao = ClaimAuditingDao.getInstance();
					DealerClaimReportDao reportDao = new DealerClaimReportDao();
					TtAsWrApplicationPO claimPO = auditingDao.queryClaimById(claimId);
					reportDao.modifyWorkOrderStatus(claimPO.getRoNo(), Constant.IS_NOT_REPORT, userId);  
				}*/
				//62、根据工时、配件、其他项目和附加工时回写索赔单中对应的结算金额和结算金额汇总
				this.modifyClaimAmount(Long.parseLong(claimId));
			}
			act.setOutData("ACTION_RESULT", 1);
			act.setOutData("FORWORD_URL", this.MANUAL_AUDITING);
				
		} catch (Exception e){
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"技术室授权审核");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	
	/*
	 * 结算室审核
	 * add by lishuai103@yahoo.cn
	 */
	public void claimMAccAuditInit(){
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		try{
			//取得该用户拥有的产地权限
			RequestWrapper request = act.getRequest();
			String yieldly = CommonUtils.findYieldlyByPoseId(logonUser.getPoseId());
			String falg = request.getParamValue("falg");
			if(falg!=null&&falg.equals("1")){
				String dealerCode1 = request.getParamValue("dealerCode1");
				yieldly = request.getParamValue("yieldly1");
				String balanceNo1 = request.getParamValue("balanceNo1");
				String startDate1 = request.getParamValue("startDate1");
				String endDate1 = request.getParamValue("endDate1");				
				act.setOutData("balanceNo1", balanceNo1);
				act.setOutData("dealerCode1", dealerCode1);
				act.setOutData("startDate1", startDate1);
				act.setOutData("endDate1", endDate1);
				act.setOutData("falg", falg);
			}
			act.setOutData("yieldly", yieldly);
			act.setForword(this.accaudit);
		} catch (Exception e){
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"结算室审核");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	
	public void claimAccAuditQuery(){
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		try {
			RequestWrapper request = act.getRequest();
			//CommonUtils.checkNull() 校验是否为空
			String dealerCode = CommonUtils.checkNull(request.getParamValue("dealerCode")); //经销商代码
			String yieldly = CommonUtils.checkNull(request.getParamValue("yieldly"));		//产地代码
			String balanceNo = CommonUtils.checkNull(request.getParamValue("balanceNo"));	//结算单号
			String status = CommonUtils.checkNull(request.getParamValue("status"));		    //结算单装备
			String startDate = CommonUtils.checkNull(request.getParamValue("startDate"));	//创建开始时间
			String endDate = CommonUtils.checkNull(request.getParamValue("endDate"));		//创建结束时间
			String yieldlys = CommonUtils.findYieldlyByPoseId(logonUser.getPoseId());       //该用户拥有的产地权限
			//当开始时间和结束时间相同时
			if(null!=startDate&&!"".equals(startDate)&&null!=endDate&&!"".equals(endDate)){
				startDate = startDate+" 00:00:00";
				endDate = endDate+" 23:59:59";
			}
			/*拼字符串(用于对多个查询多个经销商，不可模糊)if(!dealerCode.equals("")){////截串加单引号
				String[] supp = dealerCode.split(",");
				dealerCode = "";
				for(int i=0;i<supp.length;i++){
					supp[i] = "'"+supp[i]+"'";
					if(!dealerCode.equals("")){
						dealerCode += "," + supp[i];
					}else{
						dealerCode = supp[i];
					}
				}
			}*/
			auditBean bean = new auditBean();
			bean.setDealerCode(dealerCode);
			bean.setYieldly(yieldly);
			bean.setBalanceNo(balanceNo);
			bean.setStatus(status);
			bean.setStartDate(startDate);
			bean.setEndDate(endDate);
			bean.setOemCompanyId(String.valueOf(GetOemcompanyId.getOemCompanyId(logonUser)));
			bean.setYieldlys(yieldlys);
			
			ClaimManualAuditingDao dao = new ClaimManualAuditingDao();
			//分页方法 begin
			Integer curPage = request.getParamValue("curPage") != null ? Integer
					.parseInt(request.getParamValue("curPage"))
					: 1; // 处理当前页	
			PageResult<Map<String, Object>> ps = dao.queryAccAuditList(bean,curPage,Constant.PAGE_SIZE);
			//分页方法 end
			act.setOutData("ps", ps);     //向前台传的list 名称是固定的不可改必须用 ps
		}catch(Exception e) {//异常方法
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"结算室审核");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	
	/**
	 * 查询结算单对应索赔单
	 * 注：修改该查询条件时，需要同时调整逐条审核中的查询条件
	 */
	public void claimOneByOneAuditQuery(){
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		try {
			RequestWrapper request = act.getRequest();
			//CommonUtils.checkNull() 校验是否为空
			String id = request.getParamValue("id");
			String claimNo = request.getParamValue("claimNo");//索赔单ID
			String modelCode = request.getParamValue("modelCode");//车型代码
			String vin = request.getParamValue("vin");
			String claimType = request.getParamValue("CLAIM_TYPE");//索赔单类型
			String dealerCode = request.getParamValue("dealerCode");//经销商代码
			String startDate = CommonUtils.checkNull(request.getParamValue("startDate"));	//创建开始时间
			String endDate = CommonUtils.checkNull(request.getParamValue("endDate"));		//创建结束时间
			
			ClaimManualAuditingDao dao = new ClaimManualAuditingDao();
			
			//当开始时间和结束时间相同时
			if(null!=startDate&&!"".equals(startDate)&&null!=endDate&&!"".equals(endDate)){
				startDate = startDate+" 00:00:00";
				endDate = endDate+" 23:59:59";
			}
			Long userId = logonUser.getUserId();
			TcUserPO userPO = dao.queryUserById(userId);
			String authCode = "";
			if(userPO.getBalanceLevelCode()!=null)
				authCode = userPO.getBalanceLevelCode().toString();//结算授权级别代码

			auditBean bean = new auditBean();
			bean.setId(id);
			bean.setClaimNo(claimNo);
			bean.setModelCode(modelCode);
			bean.setVin(vin);
			bean.setStartDate(startDate);
			bean.setEndDate(endDate);
			bean.setOemCompanyId(String.valueOf(GetOemcompanyId.getOemCompanyId(logonUser)));
			bean.setAuthCodeOrder(authCode);
			bean.setDealerCode(dealerCode);
			bean.setClaimType(CommonUtils.checkNull(claimType));
			
			//分页方法 begin
			Integer curPage = request.getParamValue("curPage") != null ? Integer
					.parseInt(request.getParamValue("curPage"))
					: 1; // 处理当前页	
		
			Integer pageSize = 100;
			PageResult<Map<String, Object>> ps = dao.queryAccAuditById(bean,curPage,pageSize);
			//分页方法 end
			act.setOutData("ps", ps);     //向前台传的list 名称是固定的不可改必须用 ps
		}catch(Exception e) {//异常方法
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"结算室审核");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	
	/*
	 * 结算单批量审批
	 */
	public void auditAllClaim(){
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		RequestWrapper request = act.getRequest();
		String id = request.getParamValue("id");//结算单ID
		boolean flag = DBLockUtil.lock(id, DBLockUtil.BUSINESS_TYPE_01);
		if(!flag){//存在其他人在审核该结算单
			act.setOutData("returnValue", "100");
			return;
		}
		try {
			ClaimManualAuditingDao dao = new ClaimManualAuditingDao();
			
			Long userId = logonUser.getUserId();
			TcUserPO userPO = dao.queryUserById(userId);
			String authCode = "";
			if(userPO.getBalanceLevelCode()!=null)
				authCode = userPO.getBalanceLevelCode().toString();//结算授权级别代码
			if(Utility.testString(id)){
				//循环审核对应结算单中的满足用户权限的索赔单通过
				this.batchAuditing(Long.parseLong(id), authCode,userId);
				/*******mod by liuxh 20101126 批量审核结算单不更新结算单金额和状态*******/
				//更新结算单中结算金额和结算单状态
//				BalanceAuditing bAuditing = new BalanceAuditing("","");
//				bAuditing.modifyBalanceStatus(Long.parseLong(id), true,logonUser);
				/*******mod by liuxh 20101126 批量审核结算单不更新结算单金额和状态*******/
				act.setOutData("returnValue", 1);
			}else{
				act.setOutData("returnValue", 2);
			}
		}catch(Exception e) {//异常方法
			BizException e1 = new BizException(act,e,ErrorCodeConstant.SPECIAL_MEG,"结算室审核");
			logger.error(logonUser,e1);
			act.setException(e1);
		} finally{
			DBLockUtil.freeLock(id, DBLockUtil.BUSINESS_TYPE_01);
		}
	}
	
	/**
	 * 批量审核
	 * @param balanceId 结算单ID
	 * @param authCode 用户角色
	 * @param userId 用户ID
	 * @throws Exception 
	 */
	private void batchAuditing(Long balanceId,String authCode,Long userId) throws Exception{
		
		DealerBalanceDao balanceDao = DealerBalanceDao.getInstance();
		ClaimManualAuditingDao mAuditingDao = new ClaimManualAuditingDao();
		ClaimAuditingDao auditingDao = ClaimAuditingDao.getInstance();
		
		//更新索赔单同结算端关系表中的状态
		BalanceAuditingDao balanceAuditingDao = BalanceAuditingDao.getInstance();
		
		//查询结算单对应索赔单
		List<Map<String,Object>> claimList = balanceDao.queryClaimByBalanceId(balanceId,
				Constant.CLAIM_APPLY_ORD_TYPE_08.toString(),authCode);
		//循环审核每条索赔单
		for (Map<String, Object> claimMap : claimList) {
			String claimId = claimMap.get("CLAIM_ID").toString();
			//索赔申请单信息
			TtAsWrApplicationPO claimVO = auditingDao.queryClaimById(claimId);
			if(!authCode.equals(claimVO.getAuthCode())){//该索赔单已经审核过
				continue;
			}
			//2、根据索赔申请单中当前审核步骤，确定下一审核步骤
			String nextCode = this.getNextAuthCode(claimVO);
			//3、更新索赔申请单状态、下一步需要审核的级别和结算总金额
			TtAsWrApplicationPO claimPO = new TtAsWrApplicationPO();
			claimPO.setUpdateBy(userId);
			claimPO.setUpdateDate(new Date());
			claimPO.setAuthCode(nextCode);
			claimPO.setAuditType(Constant.IS_MANUAL_AUDITING+"");//人工审核标识
			
			String status = Constant.CLAIM_APPLY_ORD_TYPE_08.toString();
			//审核通过
			if(nextCode==null || "".equals(nextCode)){//不存在其他需要审核的级别,将索赔单状态修改为结算支付
				claimPO.setStatus(Constant.CLAIM_APPLY_ORD_TYPE_07);
				balanceAuditingDao.updateClaimStatus(Long.parseLong(claimId), Constant.STATUS_ENABLE);
				status = Constant.CLAIM_APPLY_ORD_TYPE_07.toString();
			}
			
			//1、记录审核授权状态过程
			this.recordAuthProcess(status,userId,
					claimId,"[批量结算审核]"," [结算审核]",true);
			//2、更新索赔申请单状态、下一步需要审核的级别和结算总金额
			mAuditingDao.updateClaimInfo(claimPO, Long.parseLong(claimId));
		}
	}
	
	/*
	 * 索赔单审核
	 */
	public void auditClaimInit(){
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		try{
			RequestWrapper request = act.getRequest();
			String id = request.getParamValue("id");//结算单ID
			String isConfirm = request.getParamValue("isConfirm");//是否进行收单操作  true: 是  false:不是
			if(!Utility.testString(isConfirm))
				isConfirm = "false";
			
			ClaimManualAuditingDao dao = new ClaimManualAuditingDao();
			TtAsWrClaimBalancePO balancePO = dao.queryBalanceOrderById(Long.parseLong(id));
			
			Long userId = logonUser.getUserId();
			TcUserPO userPO = dao.queryUserById(userId);
			String authCode = "";
			if(userPO.getBalanceLevelCode()!=null)
				authCode = userPO.getBalanceLevelCode().toString();//结算授权级别代码
			String dealerCode = request.getParamValue("dealerCode");
			String yieldly = request.getParamValue("yieldly");
			String balanceNo = request.getParamValue("balanceNo");
			String startDate = request.getParamValue("startDate");
			String endDate = request.getParamValue("endDate");
			act.setOutData("yieldly", yieldly);
			act.setOutData("balanceNo", balanceNo);
			act.setOutData("dealerCode", dealerCode);
			act.setOutData("startDate", startDate);
			act.setOutData("endDate", endDate);
			act.setOutData("balancePO", balancePO);
			act.setOutData("authCode", authCode);
			act.setOutData("id", id);
			act.setOutData("isConfirm", isConfirm);
			act.setForword(this.acconeaudit);
		} catch (Exception e){
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"索赔单审核");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	
	/**
	 * 跳转到索赔审核页(结算审核)
	 * @throws
	 */
	public void balanceAuditingPage() {
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean) act.getSession().get(
				Constant.LOGON_USER);
		try {
			ClaimBillMaintainDAO dao = ClaimBillMaintainDAO.getInstance();
			ClaimManualAuditingDao auditingDao = new ClaimManualAuditingDao();
			
			RequestWrapper request = act.getRequest();
			/******add by liuxh 20101127 增加是否重新审批标志*********/
			String isRedo=CommonUtils.checkNull(request.getParamValue("IS_REDO"));
			/******add by liuxh 20101127 增加是否重新审批标志*********/
			String id = request.getParamValue("ID");
			String balanceId = request.getParamValue("BALANCE_ID");
			String isAudit = request.getParamValue("isAudit");//是否是索赔审核（true:是，false:索赔明细查询）
			TtAsWrApplicationExtPO tawep = auditingDao.queryClaimOrderDetailById(id);
			
			//zhumingwei 2011-03-04
			List<Map<String, Object>> list = auditingDao.getAuthInfo(id);
			String APPROVAL_PERSON = ((Map)list.get(0)).get("APPROVAL_PERSON").toString();
			act.setOutData("APPROVAL_PERSON", APPROVAL_PERSON);
			
			String count = auditingDao.countRepairTimes(id);
			//zhumingwei 2011-03-04
			
			List<Map<String, Object>> customerList = dao.getVinUserName2(id);
			Map<String,Object> customerMap = new HashMap<String, Object>();
			if(customerList!=null && customerList.size()>0)
				customerMap = customerList.get(0);
			//如果是服务活动，取出活动代码与名称
			if(Constant.CLA_TYPE_06.toString().equals(tawep.getClaimType().toString())){
				List actList = auditingDao.getActivity(id);
				if(actList.size()>0){
					act.setOutData("activity", actList.get(0));
				}
			}
			//取得产地名称
			String yieldly = tawep.getYieldly();
			String yieldlyName = "";
			if(yieldly!=null){
				TcCodePO codePO = CommonUtils.findTcCodeDetailByCodeId(CommonUtils.parseInteger(yieldly));
				if(codePO!=null && codePO.getCodeDesc()!=null)
					yieldlyName = codePO.getCodeDesc();
			}
			tawep.setYieldlyName(yieldlyName);
			
			List<ClaimListBean> partls = dao.queryPartById(id); //取配件信息
			List<ClaimListBean> itemls = dao.queryItemById(id); //取工时
			
			List<TtAsWrNetitemExtPO> otherls = dao.queryOtherByid(id);//取其他项目
			List<FsFileuploadPO> attachLs = dao.queryAttById(id);//取得附件
			List<TtAsWrAppauthitemPO> appAuthls = dao.queryAppAuthInfo(id);//审核授权信息
			TtAsWrWrauthorizationPO authReason = dao.queryAuthReason(id);//需要授权原因
			List<TcCodePO> statusList =  CommonUtils.findTcCodeByType(Integer.parseInt(Constant.IF_TYPE));//是否同意状态
			 List<Map<String,Object>> listOutRepair = dao.viewOutRepair(tawep.getRoNo());//根据索赔单的工单号查询工单的外出维修信息
			act.setOutData("application", tawep);
			act.setOutData("attachLs", attachLs);
			act.setOutData("ID", id);//索赔申请单ID
			act.setOutData("BALANCE_ID", balanceId);//结算单ID
			act.setOutData("itemLs", itemls);//索赔单之工时信息
			act.setOutData("partLs", partls);//索赔单之配件信息
			act.setOutData("otherLs",otherls);//索赔单之其他项目信息
			act.setOutData("appAuthls",appAuthls);//索赔单之审核信息
			act.setOutData("authReason",authReason);//索赔单之审核原因
			act.setOutData("statusList", statusList);//是否同意状态
			act.setOutData("isAudit", isAudit);//true:审核页面 false:明细查询页面
			act.setOutData("customerMap", customerMap);//客户信息
			act.setOutData("claimId", id);//索赔单ID
			
			//zhumingwei 2011-03-04
			act.setOutData("count", count);//维修次数
			//zhumingwei 2011-03-04
			
			/*****MOD BY LIUXH 20101203 有外出维修才信息才取数据******/
			if(listOutRepair.size()>0){
				act.setOutData("listOutRepair", listOutRepair.get(0));//外出
			}
			/*****MOD BY LIUXH 20101203 有外出维修才信息才取数据******/
			
			/******add by liuxh 20101127 增加是否重新审批标志*********/
			act.setOutData("isRedo", isRedo); 
			/******add by liuxh 20101127 增加是否重新审批标志*********/
			
			//zhumingwei 2011-03-11  此方法用于区分轿车和微车
			TcCodePO codePo= new TcCodePO();
			codePo.setType(Constant.chana+"");
			TcCodePO poValue = (TcCodePO)dao.select(codePo).get(0);
			String codeId = poValue.getCodeId();
			act.setOutData("codeId", Integer.parseInt(codeId));
			//zhumingwei 2011-03-11
			
			act.setForword(this.BALANCE_AUDITING_PAGE);
		} catch (Exception e) {
			BizException e1 = new BizException(act, e,
					ErrorCodeConstant.QUERY_FAILURE_CODE, "索赔单状态跟踪");
			logger.error(logonUser, e1);
			act.setException(e1);
		}
	}
	
	/**
	 * 结算室授权审核
	 * <pre>
	 * 步骤：
	 * 1、更新索赔之配件信息（结算金额）
	 * 2、更新索赔之工时信息（结算金额）
	 * 3、更新索赔之其他项目信息（结算金额）
	 * 4、记录审核授权状态过程
	 * 5、更新索赔申请单授权，将审核授权级别中审核完成的去掉
	 * 6、更新索赔申请单状态、下一步需要审核的级别和结算总金额
	 * 7、当对应结算单中的索赔单都审核通过时，重新统计结算单中数据和结算单明细中数据
	 *    同时更改索赔单状态。
	 * </pre>
	 */
	public void balanceAuditing(){
		
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);

		try{
			RequestWrapper request = act.getRequest();
			String isReDo=CommonUtils.checkNull(request.getParamValue("isRedo"));
			Long userId = logonUser.getUserId();//登陆用户ID
			String claimId = request.getParamValue("claimId");//索赔申请单ID
			String balanceId = request.getParamValue("id");//结算单ID
			String status = request.getParamValue("status");//审核状态(审核通过、审核退回、审核拒绝)
			String partIds[] = request.getParamValues("PART_ID");//索赔之配件信息ID
			String labourIds[] = request.getParamValues("LABOUR_ID");//索赔之工时信息ID
			String otherIds[] = request.getParamValues("OTHER_ID");//索赔之其他项目信息ID
			String partBlance[] = request.getParamValues("PARTAMOUNT");//索赔之配件结算金额
			String partRemark[] = request.getParamValues("PARTREMARK");//索赔之配件之备注信息
			String partBlanceCount[] = request.getParamValues("PARTCOUNT");//索赔之配件结算数量
			String labourBlance[] = request.getParamValues("LOBOURAMOUNT");//索赔之工时结算金额
			String labourBlanceCount[] = request.getParamValues("LOBOURCOUNT");//索赔之工时结算数量
			String labourRemark[] = request.getParamValues("LOBOURREMARK");//索赔之工时之备注
			String otherBlance[] = request.getParamValues("OTHERAMOUNT");//索赔之其他项目结算金额
			String auditCon[] = request.getParamValues("audit_con");//其它费用审核意见
			String remark = request.getParamValue("CON_REMARK");//审核意见
			String isContinue = request.getParamValue("isContinue");//是否连续审核 true :连续 其他:单条审核
			String appendLabour = request.getParamValue("APPEND_LABOUR");//追加工时数
			String labourPrice = request.getParamValue("labourPrice");//工时单价
			
			
			int flag = 1;//审核标识(1:正常 2:该单已经审核过)
			if(this.isBalanceAuditing(claimId, userId,isReDo)){//不可以再次审核，该索赔单已经审核过
				flag = 2;
			}else{
				//1、更新索赔之配件信息（结算金额）
				double pBlance = this.updatePartInfo(partIds,partBlance,partBlanceCount,partRemark,userId);
				//2、更新索赔之工时信息（结算金额）
				double lBlance = this.updateLabourInfo(labourIds,labourBlance,labourBlanceCount,labourRemark,userId);
				//3、更新索赔之其他项目信息（结算金额）
				double oBlance = this.updateOtherInfo(otherIds,otherBlance,userId,auditCon);
				
				double allBlance = pBlance + lBlance + oBlance;//结算总金额
				
				//4、记录审核授权状态过程
				this.recordAuthProcess(status,userId,claimId,remark," [结算审核]",true);
				//5、根据索赔申请单中当前审核步骤，确定下一审核步骤
				String nextCode = this.getNextAuthCode(claimId);
				//6、更新索赔申请单状态、下一步需要审核的级别、结算总金额和结算工时数
				TtAsWrApplicationPO conditionPO = new TtAsWrApplicationPO();
				//conditionPO.setStatus(Integer.parseInt(status));
				conditionPO.setUpdateBy(userId);
				conditionPO.setBalanceAmount(allBlance);
				conditionPO.setRemark(remark);
				conditionPO.setId(Long.parseLong(claimId));
				/**addUser:xiongchuan addDate:2010-12-14**/
				
				/**endUser:xiongchuan endDate:2010-12-14**/
				if(!Utility.testString(labourPrice))
					labourPrice = "0";
				this.updateBalanceClaimOrder(nextCode,appendLabour,Double.parseDouble(labourPrice),conditionPO);
				//61、根据工时、配件、其他项目和附加工时回写索赔单中对应的结算金额和结算金额汇总
				this.modifyClaimAmountByBalance(Long.parseLong(claimId));
				
				/********mod by liuxh 20101126 逐条审批时关闭更新结算单状态和金额**********/
				//7、更新结算单中结算金额和结算单状态
//				BalanceAuditing bAuditing = new BalanceAuditing("","");
//				bAuditing.modifyBalanceStatus(Long.parseLong(balanceId), true,logonUser);
				/********mod by liuxh 20101126 逐条审批时关闭更新结算单状态和金额**********/
			}
			act.setOutData("isContinue", isContinue);
			act.setOutData("ISAUDITING", flag);
			act.setOutData("ACTION_RESULT", 1);
			
			if(!"true".equals(isContinue)){//单条审核
				act.setOutData("FORWORD_URL", this.MANUAL_AUDITING);
			}else{
				this.auditingOneByOne();
			}
				
		} catch (Exception e){
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"技术室授权审核");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	
	/**
	 * 更新索赔申请单信息
	 * <pre>
	 * 注意：
	 *     审核过程中有一个级别上做出审核拒绝或审核退回后则不再进行其他级别审核
	 *     如果审核通过则进行下一个级别的审核
	 * </pre>
	 * @param nextCode 需要审核的下个级别
	 * @param appendLabourNum 追加工时数
	 * @param labourPrice 工时单价
	 * @param conditionPO 需要传入参数[审核用户(更新用户ID)、结算金额、索赔申请单ID、
	 * 					  审核意见]
	 */
	private void updateBalanceClaimOrder(String nextCode,String appendLabourNum,
			Double labourPrice,TtAsWrApplicationPO conditionPO){
		
		Long userId = conditionPO.getUpdateBy();
		double allBlance = conditionPO.getBalanceAmount();
		String claimId = CommonUtils.checkNull(conditionPO.getId());
		String remark = CommonUtils.checkNull(conditionPO.getRemark());
		
		TtAsWrApplicationPO claimPO = new TtAsWrApplicationPO();
		claimPO.setUpdateBy(userId);
		claimPO.setUpdateDate(new Date());
		claimPO.setAuthCode(nextCode);
		claimPO.setAuditType(Constant.IS_MANUAL_AUDITING+"");//人工审核标识
		claimPO.setRemark(remark);

		if(appendLabourNum==null || "".equals(appendLabourNum))
			appendLabourNum = "0";
		claimPO.setAppendlabourNum(CommonUtils.parseDouble(appendLabourNum));

		//计算工时费用,同时将追加费用加入到结算金额中
		Double amount = labourPrice * CommonUtils.parseDouble(appendLabourNum);
		/**addUser:xiongchuan addDate:2010-12-14**/
		claimPO.setAppendlabourAmount(amount);
		claimPO.setBalanceAppendlabourAmount(amount);
		/**endUser:xiongchuan endDate:2010-12-14**/
		claimPO.setBalanceAmount(allBlance+amount);
		
		//审核通过
		if(nextCode==null || "".equals(nextCode)){//不存在其他需要审核的级别,将索赔单状态修改为结算支付
			claimPO.setStatus(Constant.CLAIM_APPLY_ORD_TYPE_07);
			//更新索赔单同结算端关系表中的状态
			BalanceAuditingDao balanceAuditingDao = BalanceAuditingDao.getInstance();
			balanceAuditingDao.updateClaimStatus(Long.parseLong(claimId), Constant.STATUS_ENABLE);
		}
		
		ClaimManualAuditingDao mAuditingDao = new ClaimManualAuditingDao();
		mAuditingDao.updateClaimInfo(claimPO, Long.parseLong(claimId));
	}
	
	/**
	 * 逐条审批结算单中的索赔单
	 * 注：按用户选择的的查询条件，在满足条件的数据中一条接一条审批
	 */
	public void auditingOneByOne(){
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		try{
			RequestWrapper request = act.getRequest();
			String claimNo = request.getParamValue("claimNo");//索赔单号
			String vin = request.getParamValue("vin");//VIN
			String wrGroup = request.getParamValue("modelCode");//物料组
			String dealerCode = request.getParamValue("dealerCode");//经销商代码
			String startDate = request.getParamValue("startDate");//制单开始日期
			String endDate = request.getParamValue("endDate");//制单结算日期
			String balanceId = request.getParamValue("id");//结算单ID
			String claimType = request.getParamValue("CLAIM_TYPE");//索赔单类型
			
			TtAsWrApplicationExtPO tawep = new TtAsWrApplicationExtPO();
			List<ClaimListBean> partls = new LinkedList<ClaimListBean>();
			List<ClaimListBean> itemls = new LinkedList<ClaimListBean>();
			List<TtAsWrNetitemExtPO> otherls = new LinkedList<TtAsWrNetitemExtPO>();
			List<FsFileuploadPO> attachLs = new LinkedList<FsFileuploadPO>();
			List<TtAsWrAppauthitemPO> appAuthls = new LinkedList<TtAsWrAppauthitemPO>();
			
			//zhumingwei 2011-03-04
			String count = "";
			//zhumingwei 2011-03-04
			
			TtAsWrWrauthorizationPO authReason = new TtAsWrWrauthorizationPO();
			String isAudit = request.getParamValue("isAudit");//是否是索赔审核（true:是，false:索赔明细查询）
			Map<String,Object> customerMap = new HashMap<String, Object>();
			
			String cantNotAudit=CommonUtils.checkNull(request.getParamValue("cantNotAudit"));
			
			List<TcCodePO> statusList =  CommonUtils.findTcCodeByType(Integer.parseInt(Constant.IF_TYPE));//是否同意状态
			
			claimNo = CommonUtils.checkNull(claimNo);
			vin = CommonUtils.checkNull(vin);
			wrGroup = CommonUtils.checkNull(wrGroup);
			startDate = CommonUtils.checkNull(startDate);
			endDate = CommonUtils.checkNull(endDate);
			dealerCode = CommonUtils.checkNull(dealerCode);
			
			act.setOutData("claimNo", claimNo);
			act.setOutData("vin", vin);
			act.setOutData("modelCode", wrGroup);
			act.setOutData("startDate", startDate);
			act.setOutData("endDate", endDate);
			act.setOutData("balanceId", balanceId);
			act.setOutData("CLAIM_TYPE", claimType);
			act.setOutData("dealerCode", dealerCode);
			
			ClaimManualAuditingDao auditingDao = new ClaimManualAuditingDao();
			
			Long userId = logonUser.getUserId();
			TcUserPO userPO = auditingDao.queryUserById(userId);
			String authCode = "";
			if(userPO.getBalanceLevelCode()!=null)
				authCode = userPO.getBalanceLevelCode().toString();//结算授权级别代码
			
			//查询满足条件的一条索赔单(只查询未做结算审核的索赔单)
			auditBean conditionBean = new auditBean();
			conditionBean.setClaimNo(claimNo);
			conditionBean.setVin(vin);
			conditionBean.setModelCode(wrGroup);
			conditionBean.setStartDate(Utility.testString(startDate)?(startDate+" 00:00:00"):startDate);
			conditionBean.setEndDate(Utility.testString(endDate)?(endDate+" 23:59:59"):endDate);
			conditionBean.setId(balanceId);
			conditionBean.setAuthCode(authCode);
			conditionBean.setDealerCode(dealerCode);
			conditionBean.setClaimStatus(Constant.CLAIM_APPLY_ORD_TYPE_08.toString());
			conditionBean.setClaimType(claimType);
			conditionBean.setCantNotAudit(cantNotAudit);
			
			PageResult<Map<String,Object>> claimResult = auditingDao.queryAccAuditById(conditionBean,1,1);
			List<Map<String,Object>> claimList = claimResult.getRecords();
			String hasNext = "true";
			ClaimBillMaintainDAO dao = ClaimBillMaintainDAO.getInstance();
			if(claimList!=null && claimList.size()>0){
				String claimId=claimList.get(0).get("CLAIM_ID").toString();
				
				tawep = auditingDao.queryClaimOrderDetailById(claimId);
				
				List<Map<String, Object>> customerList = dao.getVinUserName2(claimId);
				customerMap = new HashMap<String, Object>();
				if(customerList!=null && customerList.size()>0)
					customerMap = customerList.get(0);
				
				//取得产地名称
				String yieldly = tawep.getYieldly();
				String yieldlyName = "";
				if(yieldly!=null){
					TcCodePO codePO = CommonUtils.findTcCodeDetailByCodeId(CommonUtils.parseInteger(yieldly));
					if(codePO!=null && codePO.getCodeDesc()!=null)
						yieldlyName = codePO.getCodeDesc();
				}
				tawep.setYieldlyName(yieldlyName);
				
				partls = dao.queryPartById(claimId); //取配件信息
				itemls = dao.queryItemById(claimId); //取工时
				otherls = dao.queryOtherByid(claimId);//取其他项目
				attachLs = dao.queryAttById(claimId);//取得附件
				appAuthls = dao.queryAppAuthInfo(claimId);//审核授权信息
				authReason = dao.queryAuthReason(claimId);//需要授权原因
				
				//zhumingwei 2011-03-04
				count = auditingDao.countRepairTimes(claimId);
				List<Map<String, Object>> list = auditingDao.getAuthInfo(claimId);
				String APPROVAL_PERSON = ((Map)list.get(0)).get("APPROVAL_PERSON").toString();
				act.setOutData("APPROVAL_PERSON", APPROVAL_PERSON);
				//zhumingwei 2011-03-04
				
				statusList =  CommonUtils.findTcCodeByType(Integer.parseInt(Constant.IF_TYPE));//是否同意状态
			
			}else{
				hasNext = "false";
			}
			List<Map<String,Object>> listOutRepair = dao.viewOutRepair(tawep.getRoNo());//根据索赔单的工单号查询工单的外出维修信息
			if(listOutRepair.size()>0){
				act.setOutData("listOutRepair", listOutRepair.get(0));//外出
			}
			act.setOutData("application", tawep);
			act.setOutData("attachLs", attachLs);
			act.setOutData("itemLs", itemls);//索赔单之工时信息
			act.setOutData("partLs", partls);//索赔单之配件信息
			act.setOutData("otherLs",otherls);//索赔单之其他项目信息
			act.setOutData("appAuthls",appAuthls);//索赔单之审核信息
			act.setOutData("authReason",authReason);//索赔单之审核原因
			act.setOutData("isAudit", isAudit);//true:审核页面 false:明细查询页面
			act.setOutData("customerMap", customerMap);//客户信息
			act.setOutData("statusList", statusList);//是否同意状态
			act.setOutData("BALANCE_ID", balanceId);//结算单ID
			
			//zhumingwei 2011-03-04
			act.setOutData("count", count);
			//zhumingwei 2011-03-04
			
			//zhumingwei 2011-03-11  此方法用于区分轿车和微车
		    TcCodePO codePo= new TcCodePO();
		    codePo.setType(Constant.chana+"");
		    TcCodePO poValue = (TcCodePO)dao.select(codePo).get(0);
			String codeId = poValue.getCodeId();
			act.setOutData("codeId", Integer.parseInt(codeId));
			//zhumingwei 2011-03-11
			
			act.setOutData("HASNEXT", hasNext);
			act.setOutData("cantNotAudit", cantNotAudit);
			act.setOutData("isContinue", "true");
			act.setForword(this.BALANCE_AUDITING_ONEBYONE);
		} catch (Exception e){
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"结算室逐条审核");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	/**********add by liuxh 20101209 索赔单申请时跳过功能***********/
	public void auditingSkip(){
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		try{
			
			RequestWrapper request = act.getRequest();
			String claimNo = request.getParamValue("claimNo");//索赔单号
			String vin = request.getParamValue("vin");//VIN
			String wrGroup = request.getParamValue("modelCode");//物料组
			String dealerCode = request.getParamValue("dealerCode");//经销商代码
			String startDate = request.getParamValue("startDate");//制单开始日期
			String endDate = request.getParamValue("endDate");//制单结算日期
			String balanceId = request.getParamValue("id");//结算单ID
			String claimType = request.getParamValue("CLAIM_TYPE");//索赔单类型
			String cantNotAudit=CommonUtils.checkNull(request.getParamValue("cantNotAudit"));
			String claimIdCur = request.getParamValue("claimId");//索赔申请单ID	
			if(cantNotAudit.equals("")){
				cantNotAudit=claimIdCur;
			}
			else{
				cantNotAudit=cantNotAudit+","+claimIdCur;
			}
			TtAsWrApplicationExtPO tawep = new TtAsWrApplicationExtPO();
			List<ClaimListBean> partls = new LinkedList<ClaimListBean>();
			List<ClaimListBean> itemls = new LinkedList<ClaimListBean>();
			List<TtAsWrNetitemExtPO> otherls = new LinkedList<TtAsWrNetitemExtPO>();
			List<FsFileuploadPO> attachLs = new LinkedList<FsFileuploadPO>();
			List<TtAsWrAppauthitemPO> appAuthls = new LinkedList<TtAsWrAppauthitemPO>();
			TtAsWrWrauthorizationPO authReason = new TtAsWrWrauthorizationPO();
			String isAudit = request.getParamValue("isAudit");//是否是索赔审核（true:是，false:索赔明细查询）
			Map<String,Object> customerMap = new HashMap<String, Object>();
			
			List<TcCodePO> statusList =  CommonUtils.findTcCodeByType(Integer.parseInt(Constant.IF_TYPE));//是否同意状态
			
			claimNo = CommonUtils.checkNull(claimNo);
			vin = CommonUtils.checkNull(vin);
			wrGroup = CommonUtils.checkNull(wrGroup);
			startDate = CommonUtils.checkNull(startDate);
			endDate = CommonUtils.checkNull(endDate);
			dealerCode = CommonUtils.checkNull(dealerCode);
			
			act.setOutData("claimNo", claimNo);
			act.setOutData("vin", vin);
			act.setOutData("modelCode", wrGroup);
			act.setOutData("startDate", startDate);
			act.setOutData("endDate", endDate);
			act.setOutData("balanceId", balanceId);
			act.setOutData("CLAIM_TYPE", claimType);
			act.setOutData("dealerCode", dealerCode);
			
			ClaimManualAuditingDao auditingDao = new ClaimManualAuditingDao();
			
			Long userId = logonUser.getUserId();
			TcUserPO userPO = auditingDao.queryUserById(userId);
			String authCode = "";
			if(userPO.getBalanceLevelCode()!=null)
				authCode = userPO.getBalanceLevelCode().toString();//结算授权级别代码
			
			//查询满足条件的一条索赔单(只查询未做结算审核的索赔单)
			
			auditBean conditionBean = new auditBean();
			conditionBean.setClaimNo(claimNo);
			conditionBean.setVin(vin);
			conditionBean.setModelCode(wrGroup);
			conditionBean.setStartDate(Utility.testString(startDate)?(startDate+" 00:00:00"):startDate);
			conditionBean.setEndDate(Utility.testString(endDate)?(endDate+" 23:59:59"):endDate);
			conditionBean.setId(balanceId);
			conditionBean.setAuthCode(authCode);
			conditionBean.setDealerCode(dealerCode);
			conditionBean.setClaimStatus(Constant.CLAIM_APPLY_ORD_TYPE_08.toString());
			conditionBean.setClaimType(claimType);
			conditionBean.setCantNotAudit(cantNotAudit);
			
			PageResult<Map<String,Object>> claimResult = auditingDao.queryAccAuditSkipById(conditionBean,1,1);
			List<Map<String,Object>> claimList = claimResult.getRecords();
			String hasNext = "true";
			ClaimBillMaintainDAO dao = ClaimBillMaintainDAO.getInstance();
			if(claimList!=null && claimList.size()>0){
				String claimId=claimList.get(0).get("CLAIM_ID").toString();
				
				tawep = auditingDao.queryClaimOrderDetailById(claimId);
				
				List<Map<String, Object>> customerList = dao.getVinUserName2(claimId);
				customerMap = new HashMap<String, Object>();
				if(customerList!=null && customerList.size()>0)
					customerMap = customerList.get(0);
				//如果是服务活动，取出活动代码与名称
				if(Constant.CLA_TYPE_06.toString().equals(tawep.getClaimType().toString())){
					List actList = auditingDao.getActivity(claimId);
					if(actList.size()>0){
						act.setOutData("activity", actList.get(0));
					}
				}
				//取得产地名称
				String yieldly = tawep.getYieldly();
				String yieldlyName = "";
				if(yieldly!=null){
					TcCodePO codePO = CommonUtils.findTcCodeDetailByCodeId(CommonUtils.parseInteger(yieldly));
					if(codePO!=null && codePO.getCodeDesc()!=null)
						yieldlyName = codePO.getCodeDesc();
				}
				tawep.setYieldlyName(yieldlyName);
				
				partls = dao.queryPartById(claimId); //取配件信息
				itemls = dao.queryItemById(claimId); //取工时
				otherls = dao.queryOtherByid(claimId);//取其他项目
				attachLs = dao.queryAttById(claimId);//取得附件
				appAuthls = dao.queryAppAuthInfo(claimId);//审核授权信息
				authReason = dao.queryAuthReason(claimId);//需要授权原因
				statusList =  CommonUtils.findTcCodeByType(Integer.parseInt(Constant.IF_TYPE));//是否同意状态
				//zhumingwei 2011-03-10
				String count = auditingDao.countRepairTimes(claimId);
				act.setOutData("count", count);
				List<Map<String, Object>> list = auditingDao.getAuthInfo(claimId);
				String APPROVAL_PERSON = ((Map)list.get(0)).get("APPROVAL_PERSON").toString();
				act.setOutData("APPROVAL_PERSON", APPROVAL_PERSON);
				//zhumingwei 2011-03-10
			}else{
				hasNext = "false";
			}
			List<Map<String,Object>> listOutRepair = dao.viewOutRepair(tawep.getRoNo());//根据索赔单的工单号查询工单的外出维修信息
			if(listOutRepair.size()>0){
				act.setOutData("listOutRepair", listOutRepair.get(0));//外出
			}
			
			act.setOutData("application", tawep);
			act.setOutData("attachLs", attachLs);
			act.setOutData("itemLs", itemls);//索赔单之工时信息
			act.setOutData("partLs", partls);//索赔单之配件信息
			act.setOutData("otherLs",otherls);//索赔单之其他项目信息
			act.setOutData("appAuthls",appAuthls);//索赔单之审核信息
			act.setOutData("authReason",authReason);//索赔单之审核原因
			act.setOutData("isAudit", isAudit);//true:审核页面 false:明细查询页面
			act.setOutData("customerMap", customerMap);//客户信息
			act.setOutData("statusList", statusList);//是否同意状态
			act.setOutData("BALANCE_ID", balanceId);//结算单ID
			act.setOutData("HASNEXT", hasNext);
			act.setOutData("isContinue", "true");
			act.setOutData("cantNotAudit", cantNotAudit);
			
			//zhumingwei 2011-03-11  此方法用于区分轿车和微车
		    TcCodePO codePo= new TcCodePO();
		    codePo.setType(Constant.chana+"");
		    TcCodePO poValue = (TcCodePO)dao.select(codePo).get(0);
			String codeId = poValue.getCodeId();
			act.setOutData("codeId", Integer.parseInt(codeId));
			//zhumingwei 2011-03-11
			act.setForword(this.BALANCE_AUDITING_ONEBYONE);
		} catch (Exception e){
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"结算室逐条审核");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	/**********add by liuxh 20101209 索赔单申请时跳过功能***********/
	/**
	 * 更新索赔单中的结算金额
	 * @param claimId
	 */
	public void modifyClaimAmount(Long claimId){
		
		ClaimManualAuditingDao mAuditingDao = new ClaimManualAuditingDao();
		//当索赔单类型为 退回时 更新所有子表(配件、工时和其他项目)审核状态和金额
		mAuditingDao.modifyBackClaimDetail(claimId);
		//更新结算工时、配件、和其他项目金额
		mAuditingDao.modifyClaimBalanceDetailAmount(claimId,true);
		//更新索赔单总结算金额
		mAuditingDao.modifyClaimBalanceAmount(claimId,true);
		mAuditingDao.modifyClaimBalanceAmount2(claimId, true);
	}
	
	/**
	 * 结算单更新索赔单中的结算金额
	 * @param claimId
	 */
	public void modifyClaimAmountByBalance(Long claimId){
		ClaimManualAuditingDao mAuditingDao = new ClaimManualAuditingDao();
		//更新结算工时、配件、和其他项目金额
		mAuditingDao.modifyClaimBalanceDetailAmount(claimId,false);
		//更新索赔单总结算金额
		mAuditingDao.modifyClaimBalanceAmount(claimId,false);
		
	}
	
	/**
	 * 索赔申请重新审核作业 初始化
	 */
	public void claimReAuditingInit(){
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		try{
			//取得该用户拥有的产地权限
			String yieldly = CommonUtils.findYieldlyByPoseId(logonUser.getPoseId());
			
			act.setOutData("yieldly", yieldly);
			act.setForword(this.MANUAL_REAUDITING);
		} catch (Exception e){
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,this.FUNCTION_DESC);
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	
	/**
	 * 索赔申请单重新审核查询
	 * 规则：
	 */
	public void claimManualReAuditingQuery(){
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		ClaimManualAuditingDao maDao = new ClaimManualAuditingDao();
		try{
			//取得查询参数
			RequestWrapper request = act.getRequest();
			String dealerCode = request.getParamValue("dealerCode");//经销商代码（多个）
			String dealerName = request.getParamValue("DEALER_NAME");//经销商名称
			String roNo = request.getParamValue("CON_RO_NO");//工单号
			String lineNo = request.getParamValue("CON_LINE_NO");//行号
			String claimType = request.getParamValue("CLAIM_TYPE");//索赔类型
			String vin = request.getParamValue("CON_VIN");//车辆唯一标识码
			String applyStartDate = request.getParamValue("CON_APPLY_DATE_START");//申请日期范围（开始时间）
			String applyEndDate = request.getParamValue("CON_APPLY_DATE_END");//申请日期范围（结束时间）
			String claimStatus = Constant.CLAIM_APPLY_ORD_TYPE_04.toString();//状态 固定为 "审核通过"
			String claimNo = request.getParamValue("CLAIM_NO");//索赔申请单号
			Long companyId = GetOemcompanyId.getOemCompanyId(logonUser);//用户所属公司
			String status = request.getParamValue("STATUS");//索赔单状态
			String yieldly = request.getParamValue("YIELDLY");//查询条件--产地
			String yieldlys = CommonUtils.findYieldlyByPoseId(logonUser.getPoseId());//该用户拥有的产地权限
			Long orgId = logonUser.getOrgId();//组织ID
			Long poseId = logonUser.getPoseId();//职位ID
			//查询职位中业务范围
			String areaIds = MaterialGroupManagerDao.getAreaIdsByPoseId(poseId);
			//添加审核时间，审核人查询条件
			String approveDate = request.getParamValue("approveDate");
			String approveDate2 = request.getParamValue("approveDate2");
			String approveName = request.getParamValue("approveName");
			
			Integer curPage = request.getParamValue("curPage")==null?1
					:Integer.parseInt(request.getParamValue("curPage"));//分页首页代码
			
			if(Utility.testString(applyStartDate))
				applyStartDate = applyStartDate + " 00:00:00";
			
			if(Utility.testString(applyEndDate))
				applyEndDate = applyEndDate + " 23:59:59";
			
			ClaimOrderBean orderBean = new ClaimOrderBean();
			orderBean.setDealerCodes(dealerCode);
			orderBean.setDealerName(dealerName);
			orderBean.setRoNo(roNo);
			orderBean.setLineNo(lineNo);
			orderBean.setClaimType(claimType);
			orderBean.setVin(vin);
			orderBean.setApplyEndDate(applyEndDate);
			orderBean.setApplyStartDate(applyStartDate);
			orderBean.setClaimStatus(claimStatus);
			orderBean.setClaimNo(claimNo);
			orderBean.setCompanyId(companyId);
			orderBean.setPoseId(poseId);
			orderBean.setOrgId(orgId);
			orderBean.setAreaIds(CommonUtils.checkNull(areaIds));
			orderBean.setYieldly(yieldly);
			orderBean.setYieldlys(yieldlys);
			orderBean.setStatus(status);
			orderBean.setApproveDate(approveDate);
			orderBean.setApproveDate2(approveDate2);
			orderBean.setApproveName(approveName);
			//查询索赔申请单
			PageResult<Map<String,Object>> result = maDao.queryClaim(orderBean,curPage,
															Constant.PAGE_SIZE);
			
			act.setOutData("ps", result);
		} catch (Exception e){
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"索赔申请单上报");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	
	/**
	 * 重新授权审核
	 * <pre>
	 * 步骤：
	 * 1、更新索赔之配件信息（结算金额）
	 * 2、更新索赔之工时信息（结算金额）
	 * 3、更新索赔之其他项目信息（结算金额）
	 * 4、记录审核授权状态过程
	 * 5、更新索赔申请单授权，将审核授权级别中审核完成的去掉
	 * 6、更新索赔申请单状态、下一步需要审核的级别和结算总金额
	 * </pre>
	 */
	public void reAuditing(){
		
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);

		try{
			RequestWrapper request = act.getRequest();
			Long userId = logonUser.getUserId();//登陆用户ID
			String claimId = request.getParamValue("claimId");//索赔申请单ID
			String status = request.getParamValue("status");//审核状态(审核通过、审核退回、审核拒绝)
			String partIds[] = request.getParamValues("PART_ID");//索赔之配件信息ID
			String labourIds[] = request.getParamValues("LABOUR_ID");//索赔之工时信息ID
			String otherIds[] = request.getParamValues("OTHER_ID");//索赔之其他项目信息ID
			String partBlance[] = request.getParamValues("PARTAMOUNTTD");//索赔之配件结算金额
			String labourBlance[] = request.getParamValues("LOBOURAMOUNTTD");//索赔之工时结算金额
			String otherBlance[] = request.getParamValues("OTHERAMOUNT");//索赔之其他项目结算金额
			String partStatus[] = request.getParamValues("PARTSTATUS");//索赔之配件结算金额
			String labourStatus[] = request.getParamValues("LOBOURSTATUS");//索赔之工时结算金额
			String partCount[] = request.getParamValues("PARTBCOUNTTD");//索赔之配件结算数量
			String labourCount[] = request.getParamValues("LABOURBCOUNTTD");//索赔之工时结算数量
			String otherStatus[] = request.getParamValues("OTHERSTATUS");//索赔之其他项目结算金额
			String remark = request.getParamValue("CON_REMARK");//审核意见
			String appendLabour = request.getParamValue("APPEND_LABOUR");//追加工时数
			String labourPrice = request.getParamValue("labourPrice");//工时单价
			
			remark = CommonUtils.checkNull(remark) + " [追加工时数：" +appendLabour+ "]";
			
			
			//1、更新索赔之配件信息（结算金额）
			double pBlance = this.updatePartInfoByStatus(partIds,partBlance,partStatus,partCount,userId);
			//2、更新索赔之工时信息（结算金额）
			double lBlance = this.updateLabourInfoByStatus(labourIds,labourBlance,labourStatus,labourCount,userId);
			//3、更新索赔之其他项目信息（结算金额）
			double oBlance = this.updateOtherInfoByStatus(otherIds,otherBlance,otherStatus,userId);
			
			double allBlance = pBlance + lBlance + oBlance;//结算总金额
			
			//4、记录审核授权状态过程
			this.recordAuthProcess(status,userId,claimId,remark," [重授权审核]",false);
			//5、更新索赔申请单状态、下一步需要审核的级别和结算总金额
			//this.updateClaimOrder(status,userId,allBlance,claimId,"",remark,appendLabour,companyId);
			TtAsWrApplicationPO conditionPO = new TtAsWrApplicationPO();
			conditionPO.setStatus(Integer.parseInt(status));
			conditionPO.setAuthCode(""); //清空审核级别
			conditionPO.setUpdateBy(userId);
			conditionPO.setBalanceAmount(allBlance);
			conditionPO.setRemark(remark);
			conditionPO.setId(Long.parseLong(claimId));
			
			if(!Utility.testString(labourPrice)||Constant.CLAIM_APPLY_ORD_TYPE_06.toString().equals(status))
				labourPrice = "0";
			if(Constant.CLAIM_APPLY_ORD_TYPE_06.toString().equals(status))
				appendLabour = "0";
			this.updateClaimOrder("",appendLabour,Double.parseDouble(labourPrice),conditionPO);
			//51、根据工时、配件、其他项目和附加工时回写索赔单中对应的结算金额和结算金额汇总
			this.modifyClaimAmount(Long.parseLong(claimId));
			act.setOutData("ACTION_RESULT", 1);
			act.setOutData("FORWORD_URL", this.MANUAL_REAUDITING);
				
		} catch (Exception e){
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"技术室授权审核");
			logger.error(logonUser,e1);
			act.setException(e1);
		}
	}
	
	/**
	 * 结算室审核(批量审核)
	 */
	public void batchAuditingBlance(){
		ActionContext act = ActionContext.getContext();
		AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
		
		RequestWrapper request = act.getRequest();
		String claimIds[] = request.getParamValues("claimId");//索赔单ID
		String id = request.getParamValue("id");//结算单ID
		boolean flag = DBLockUtil.lock(id, DBLockUtil.BUSINESS_TYPE_01);
		if(!flag){
			act.setOutData("SUCCESS", "LOCK");
			return;
		}
		try{
			ClaimManualAuditingDao dao = new ClaimManualAuditingDao();
			BalanceAuditingDao balanceAuditingDao = BalanceAuditingDao.getInstance();
			ClaimAuditingDao auditingDao = ClaimAuditingDao.getInstance();
			
			if(claimIds!=null && claimIds.length>0){
				Long userId = logonUser.getUserId();
				TcUserPO userPO = dao.queryUserById(userId);
				String authCode = "";
				if(userPO.getBalanceLevelCode()!=null)
					authCode = userPO.getBalanceLevelCode().toString();//结算授权级别代码
				
				for(int k=0;k<claimIds.length;k++){
					String claimId = claimIds[k];
					//索赔申请单信息
					TtAsWrApplicationPO claimVO = auditingDao.queryClaimById(claimId);
					if(!authCode.equals(claimVO.getAuthCode())){//该索赔单已经审核过
						continue;
					}
					//2、根据索赔申请单中当前审核步骤，确定下一审核步骤
					String nextCode = this.getNextAuthCode(claimVO);
					//3、更新索赔申请单状态、下一步需要审核的级别和结算总金额
					TtAsWrApplicationPO claimPO = new TtAsWrApplicationPO();
					claimPO.setUpdateBy(userId);
					claimPO.setUpdateDate(new Date());
					claimPO.setAuthCode(nextCode);
					claimPO.setAuditType(Constant.IS_MANUAL_AUDITING+"");//人工审核标识
					
					String status = Constant.CLAIM_APPLY_ORD_TYPE_08.toString();
					//审核通过
					if(nextCode==null || "".equals(nextCode)){//不存在其他需要审核的级别,将索赔单状态修改为结算支付
						claimPO.setStatus(Constant.CLAIM_APPLY_ORD_TYPE_07);
						balanceAuditingDao.updateClaimStatus(Long.parseLong(claimId), Constant.STATUS_ENABLE);
						status = Constant.CLAIM_APPLY_ORD_TYPE_07.toString();
					}
					
					//1、记录审核授权状态过程
					this.recordAuthProcess(status,userId,
							claimId,"[批量结算审核]"," [结算审核]",true);
					//2、更新索赔申请单状态、下一步需要审核的级别和结算总金额
					dao.updateClaimInfo(claimPO, Long.parseLong(claimId));
				}
			}
			/******mod by liuxh 20101126 批量审核索赔单时不调用更新结算单状态和结算金额******/
			//更新结算单中结算金额和结算单状态
//			BalanceAuditing bAuditing = new BalanceAuditing("","");
//			bAuditing.modifyBalanceStatus(Long.parseLong(id), true, logonUser);
			/******mod by liuxh 20101126 批量审核索赔单时不调用更新结算单状态和结算金额******/
			
			act.setOutData("SUCCESS", "SUCCESS");
		} catch (Exception e){
			BizException e1 = new BizException(act,e,ErrorCodeConstant.QUERY_FAILURE_CODE,"结算室批量审核");
			logger.error(logonUser,e1);
			act.setOutData("SUCCESS", "FAILURE");
			act.setException(e1);
		} finally {
			DBLockUtil.freeLock(id, DBLockUtil.BUSINESS_TYPE_01);
		}
	}
	/********add by liuxh 20101126 增加结算室审核完成功能  调用更新结算标志和重新计算**********/
	public void settComplete(){
		ActionContext act = ActionContext.getContext();
		try
		{	
			AclUserBean logonUser = (AclUserBean)act.getSession().get(Constant.LOGON_USER);
			RequestWrapper request = act.getRequest();
			String blanceId=CommonUtils.checkNull(request.getParamValue("blanceId"));
			BalanceAuditing bAuditing = new BalanceAuditing("","");
			
			DealerBalanceDao balanceDao = DealerBalanceDao.getInstance();
			
			/*********判断索赔单是否全部审核完成**********/
			boolean flagClaim=balanceDao.queryClaimByBanlanceId(Long.parseLong(blanceId));
			boolean flagSp=balanceDao.querySpecByBanlanceId(Long.parseLong(blanceId));
			if(!flagClaim){
				throw new BizException("结算单下的索赔单未完全审核完成!");
			}
			if(!flagSp){
				throw new BizException("结算单下的特殊费用工单未完全审核完成!");
			}
			/*********判断索赔单是否全部审核完成**********/
			
			
			//2、根据标识的状态和特殊费用的状态统计特殊费用
			List<Map<String,Object>> feeList = balanceDao.getSpecialFeeByBalanceIdStatus(Long.parseLong(blanceId));
			double marketFee = 0;//市场工单费用
			double outFee = 0;   //特殊外出费用
			int feeCount = 0;
			if(feeList!=null && feeList.size()>0){
				for (Map<String, Object> feeMap : feeList) {
					if(feeMap.containsKey("FEE_TYPE")){
						if((Constant.FEE_TYPE_01).equals(feeMap.get("FEE_TYPE").toString())){
							if(feeMap.containsKey("DECLARE_SUM")){
								marketFee = ((BigDecimal)feeMap.get("DECLARE_SUM")).doubleValue();
							}
							if(feeMap.containsKey("FEETYPECOUNT")){
								feeCount = feeCount + ((BigDecimal)feeMap.get("FEETYPECOUNT")).intValue();
							}
						}else if(Constant.FEE_TYPE_02.equals(feeMap.get("FEE_TYPE").toString())){
							if(feeMap.containsKey("DECLARE_SUM")){
								outFee = ((BigDecimal)feeMap.get("DECLARE_SUM")).doubleValue();
							}
							if(feeMap.containsKey("FEETYPECOUNT")){
								feeCount = feeCount + ((BigDecimal)feeMap.get("FEETYPECOUNT")).intValue();
							}
						}
					}
				}
			}else{
				feeCount = 0;
			}
			
			//3、将特殊费用合计到结算单中
			balanceDao.addSpecialFeeToBalanceOrder(Long.parseLong(blanceId), marketFee, outFee, feeCount);
			balanceDao.updateMarkSpeeActiveFee(Long.parseLong(blanceId));//add by liuxh 20101227 完成时记录市场公单和外出公单费用
			bAuditing.modifyBalanceStatus(Long.parseLong(blanceId), true,logonUser);
			act.setOutData("msg", "true");
		}
		catch(Exception e){
			e.printStackTrace();
			logger.error(e);
			act.setException(e);
		}
		
		
	}
	/********add by liuxh 20101126 增加结算室审核完成功能  调用更新结算标志和重新计算**********/
	
	/**
	 * 创建锁
	 * @param key
	 * @param lockMap
	 * @return boolean false : 对应key正被锁定，true 为锁定
	 */
	@SuppressWarnings("unused")
	private boolean createLock(String key,Map<String,Long> lockMap){
		
		boolean result = false;
		if(!Utility.testString(key))
			return result;
		
		if(lockMap==null){
			lockMap = new HashMap<String, Long>();
		}
		
		if(lockMap.containsKey(key)){
			Long lockTime = lockMap.get(key);
			Long nowTime = (new Date()).getTime();
			if((nowTime-lockTime)/(60*1000)>lockLimit){
				lockMap.remove(key);
				lockMap.put(key, nowTime);
				result = true;
			}else{
				result = false;;
			}
		}else{
			lockMap.put(key, (new Date()).getTime());
			result = true;
		}
		
		return result;
	}
	
	/**
	 * 释放锁
	 * @param key
	 * @param lockMap
	 */
	@SuppressWarnings("unused")
	private void releaseLock(String key,Map<String,Long> lockMap){
		if(Utility.testString(key) && lockMap!=null){
			if(lockMap.containsKey(key))
				lockMap.remove(key);
		}
	}
	
}
